Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rust_seminar_generators
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jost Hermann Triller
rust_seminar_generators
Commits
6738e263
Commit
6738e263
authored
1 year ago
by
Aleksander Salek
Browse files
Options
Downloads
Patches
Plain Diff
last final touch
parent
ab6ab9e2
Branches
main
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
benches/custom_generator_benchmark.rs
+87
-17
87 additions, 17 deletions
benches/custom_generator_benchmark.rs
src/nightly_gen/mod.rs
+0
-1
0 additions, 1 deletion
src/nightly_gen/mod.rs
with
87 additions
and
18 deletions
benches/custom_generator_benchmark.rs
+
87
−
17
View file @
6738e263
...
@@ -82,12 +82,12 @@ fn infinite_nightly(n: u64) -> u64 {
...
@@ -82,12 +82,12 @@ fn infinite_nightly(n: u64) -> u64 {
result
.iter
()
.sum
()
result
.iter
()
.sum
()
}
}
fn
gen_inside_gen_our
(
n
:
u64
)
{
fn
gen_inside_gen_our
()
{
let
vecs
=
Generator
::
new
(
Box
::
new
(|
g
|
{
let
vecs
=
Generator
::
new
(
Box
::
new
(|
g
|
{
let
fib
=
Generator
::
new
(
Box
::
new
(|
g
|
{
let
fib
=
Generator
::
new
(
Box
::
new
(|
g
|
{
let
mut
i
=
1
;
let
mut
i
=
1
;
let
mut
j
=
1
;
let
mut
j
=
1
;
while
i
<
10_000
{
while
i
<
1
_00
0_000
{
g
.suspend
(
i
);
g
.suspend
(
i
);
i
=
i
+
j
;
i
=
i
+
j
;
j
=
i
-
j
;
j
=
i
-
j
;
...
@@ -96,7 +96,7 @@ fn gen_inside_gen_our(n: u64) {
...
@@ -96,7 +96,7 @@ fn gen_inside_gen_our(n: u64) {
for
i
in
fib
{
for
i
in
fib
{
let
mut
v
=
Vec
::
new
();
let
mut
v
=
Vec
::
new
();
for
j
in
i
..
i
+
n
{
for
j
in
i
..
i
+
10
{
v
.push
(
j
);
v
.push
(
j
);
}
}
g
.suspend
(
v
);
g
.suspend
(
v
);
...
@@ -108,14 +108,14 @@ fn gen_inside_gen_our(n: u64) {
...
@@ -108,14 +108,14 @@ fn gen_inside_gen_our(n: u64) {
}
}
}
}
fn
gen_inside_gen_nightly
(
n
:
u64
)
{
fn
gen_inside_gen_nightly
()
{
let
vecs_gen
=
Gen
::
new
(||
{
let
vecs_gen
=
Gen
::
new
(||
{
Box
::
new
(
move
||
{
Box
::
new
(
move
||
{
let
fib_gen
=
Gen
::
new
(||
{
let
fib_gen
=
Gen
::
new
(||
{
Box
::
new
(
move
||
{
Box
::
new
(
move
||
{
let
mut
i
=
1
;
let
mut
i
=
1
;
let
mut
j
=
1
;
let
mut
j
=
1
;
while
i
<
10_000
{
while
i
<
1
_00
0_000
{
yield
i
;
yield
i
;
i
=
i
+
j
;
i
=
i
+
j
;
j
=
i
-
j
;
j
=
i
-
j
;
...
@@ -125,7 +125,7 @@ fn gen_inside_gen_nightly(n: u64) {
...
@@ -125,7 +125,7 @@ fn gen_inside_gen_nightly(n: u64) {
for
i
in
fib_gen
{
for
i
in
fib_gen
{
let
mut
v
=
Vec
::
new
();
let
mut
v
=
Vec
::
new
();
for
j
in
i
..
i
+
n
{
for
j
in
i
..
i
+
10
{
v
.push
(
j
);
v
.push
(
j
);
}
}
yield
v
;
yield
v
;
...
@@ -171,6 +171,56 @@ fn gen_rcs_nightly(n: u64) {
...
@@ -171,6 +171,56 @@ fn gen_rcs_nightly(n: u64) {
}
}
}
}
fn
gen_return_big_vec_nightly
()
{
let
rcs_gen
=
Gen
::
new
(||
{
Box
::
new
(
move
||
{
let
array
:
[
i32
;
100_000
]
=
[
0
;
100_000
];
yield
array
;
})
});
let
mut
result
=
Vec
::
new
();
for
rc
in
rcs_gen
{
result
.push
(
rc
);
}
}
fn
gen_return_big_vec_our
()
{
let
rcs
=
Generator
::
new
(
Box
::
new
(|
g
|
{
let
array
:
[
i32
;
100_000
]
=
[
0
;
100_000
];
g
.suspend
(
array
);
}));
let
mut
result
=
Vec
::
new
();
for
i
in
rcs
{
result
.push
(
i
);
}
}
fn
gen_one_num_nightly
()
{
let
rcs_gen
=
Gen
::
new
(||
{
Box
::
new
(
move
||
{
yield
5
;
})
});
let
mut
result
=
Vec
::
new
();
for
rc
in
rcs_gen
{
result
.push
(
rc
);
}
}
fn
gen_one_num_our
()
{
let
rcs
=
Generator
::
new
(
Box
::
new
(|
g
|
{
g
.suspend
(
5
);
}));
let
mut
result
=
Vec
::
new
();
for
i
in
rcs
{
result
.push
(
i
);
}
}
fn
bench_fibs
(
c
:
&
mut
Criterion
)
{
fn
bench_fibs
(
c
:
&
mut
Criterion
)
{
let
mut
group
=
c
.benchmark_group
(
"Fibo"
);
let
mut
group
=
c
.benchmark_group
(
"Fibo"
);
for
i
in
[
20u64
,
30u64
,
50u64
,
100u64
,
2000u64
,
100_000u64
]
.iter
()
{
for
i
in
[
20u64
,
30u64
,
50u64
,
100u64
,
2000u64
,
100_000u64
]
.iter
()
{
...
@@ -186,7 +236,7 @@ fn bench_fibs(c: &mut Criterion) {
...
@@ -186,7 +236,7 @@ fn bench_fibs(c: &mut Criterion) {
fn
bench_infinit
(
c
:
&
mut
Criterion
)
{
fn
bench_infinit
(
c
:
&
mut
Criterion
)
{
let
mut
group
=
c
.benchmark_group
(
"Infinite"
);
let
mut
group
=
c
.benchmark_group
(
"Infinite"
);
for
i
in
[
200u64
,
300u64
,
500u64
,
1_000u64
,
2_000u64
,
5
0
_000
]
.iter
()
{
for
i
in
[
200u64
,
300u64
,
500u64
,
1_000u64
,
2_000u64
,
5_000
u64
,
10_000u64
,
25_000u64
,
50_000u64
]
.iter
()
{
group
.bench_with_input
(
BenchmarkId
::
new
(
"Our Generator"
,
i
),
i
,
|
b
,
i
|
{
group
.bench_with_input
(
BenchmarkId
::
new
(
"Our Generator"
,
i
),
i
,
|
b
,
i
|
{
b
.iter
(||
infinite_our
(
*
i
))
b
.iter
(||
infinite_our
(
*
i
))
});
});
...
@@ -199,14 +249,12 @@ fn bench_infinit(c: &mut Criterion) {
...
@@ -199,14 +249,12 @@ fn bench_infinit(c: &mut Criterion) {
fn
bench_gen_in_gen
(
c
:
&
mut
Criterion
)
{
fn
bench_gen_in_gen
(
c
:
&
mut
Criterion
)
{
let
mut
group
=
c
.benchmark_group
(
"Gen_In_Gen"
);
let
mut
group
=
c
.benchmark_group
(
"Gen_In_Gen"
);
for
i
in
[
200u64
,
300u64
,
500u64
,
1_000u64
,
2_000u64
]
.iter
()
{
group
.bench_function
(
"OG - 1 Big array"
,
move
|
b
|
{
group
.bench_with_input
(
BenchmarkId
::
new
(
"Our Generator"
,
i
),
i
,
|
b
,
i
|
{
b
.iter
(||
gen_inside_gen_our
());
b
.iter
(||
gen_inside_gen_our
(
*
i
))
});
});
group
.bench_function
(
"NG - 1 Big array"
,
move
|
b
|
{
group
.bench_with_input
(
BenchmarkId
::
new
(
"Nightly Generator"
,
i
),
i
,
|
b
,
i
|
{
b
.iter
(||
gen_inside_gen_nightly
());
b
.iter
(||
gen_inside_gen_nightly
(
*
i
))
});
});
}
group
.finish
();
group
.finish
();
}
}
...
@@ -223,12 +271,34 @@ fn bench_rcs(c: &mut Criterion) {
...
@@ -223,12 +271,34 @@ fn bench_rcs(c: &mut Criterion) {
group
.finish
();
group
.finish
();
}
}
fn
bench_big
(
c
:
&
mut
Criterion
)
{
let
mut
group
=
c
.benchmark_group
(
"Big Array"
);
group
.bench_function
(
"OG - 1 Big array"
,
move
|
b
|
{
b
.iter
(||
gen_return_big_vec_our
());
});
group
.bench_function
(
"NG - 1 Big array"
,
move
|
b
|
{
b
.iter
(||
gen_return_big_vec_nightly
());
});
group
.finish
();
}
fn
bench_one
(
c
:
&
mut
Criterion
){
let
mut
group
=
c
.benchmark_group
(
"One Yield"
);
group
.bench_function
(
"OG - One yield"
,
move
|
b
|
{
b
.iter
(||
gen_one_num_our
());
});
group
.bench_function
(
"NG - One yield"
,
move
|
b
|
{
b
.iter
(||
gen_one_num_nightly
());
});
group
.finish
();
}
criterion_group!
(
criterion_group!
(
benches
,
benches
,
bench_fibs
,
//
bench_fibs,
bench_infinit
,
bench_infinit
,
bench_gen_in_gen
,
bench_gen_in_gen
,
bench_rcs
//bench_rcs,
bench_one
,
bench_big
);
);
criterion_main!
(
benches
);
criterion_main!
(
benches
);
...
...
This diff is collapsed.
Click to expand it.
src/nightly_gen/mod.rs
+
0
−
1
View file @
6738e263
...
@@ -106,7 +106,6 @@ mod tests {
...
@@ -106,7 +106,6 @@ mod tests {
]
]
);
);
}
}
#[test]
#[test]
fn
factorial
()
{
fn
factorial
()
{
let
fact_gen
=
Gen
::
new
(||
{
let
fact_gen
=
Gen
::
new
(||
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment