Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PLNK - a simple Rust benchmark framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STEVAN Antoine
PLNK - a simple Rust benchmark framework
Commits
3a515bf1
Unverified
Commit
3a515bf1
authored
Apr 24, 2024
by
STEVAN Antoine
Browse files
Options
Downloads
Patches
Plain Diff
don't store "rng" in Bencher
now that the closures can capture the outer scope, it's become useless.
parent
165751a4
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+6
-5
6 additions, 5 deletions
README.md
examples/arithmetic.rs
+6
-5
6 additions, 5 deletions
examples/arithmetic.rs
examples/capture.rs
+2
-2
2 additions, 2 deletions
examples/capture.rs
src/lib.rs
+3
-9
3 additions, 9 deletions
src/lib.rs
with
17 additions
and
21 deletions
README.md
+
6
−
5
View file @
3a515bf1
...
...
@@ -11,18 +11,19 @@ cargo add plnk --git https://gitlab.isae-supaero.fr/a.stevan/plnk --tag 0.2.0 #
use
rand
::
Rng
;
fn
arithmetic
(
b
:
&
mut
plnk
::
Bencher
)
{
plnk
::
bench
(
b
,
"addition"
,
|
_
|
plnk
::
timeit
(||
1
+
2
));
plnk
::
bench
(
b
,
"substraction"
,
|
_
|
plnk
::
timeit
(||
1
-
2
));
plnk
::
bench
(
b
,
"multiplication"
,
|
_
|
plnk
::
timeit
(||
2
*
3
));
plnk
::
bench
(
b
,
"addition"
,
||
plnk
::
timeit
(||
1
+
2
));
plnk
::
bench
(
b
,
"substraction"
,
||
plnk
::
timeit
(||
1
-
2
));
plnk
::
bench
(
b
,
"multiplication"
,
||
plnk
::
timeit
(||
2
*
3
));
}
fn
random
(
b
:
&
mut
plnk
::
Bencher
)
{
plnk
::
bench
(
b
,
"sampling"
,
|
rng
|
plnk
::
timeit
(||
rng
.gen
::
<
u128
>
()));
let
mut
rng
=
rand
::
thread_rng
();
plnk
::
bench
(
b
,
"sampling"
,
||
plnk
::
timeit
(||
rng
.gen
::
<
u128
>
()));
}
fn
main
()
{
const
NB_MEASUREMENTS
:
usize
=
10
;
let
bencher
=
plnk
::
Bencher
::
new
(
NB_MEASUREMENTS
,
rand
::
thread_rng
()
);
let
bencher
=
plnk
::
Bencher
::
new
(
NB_MEASUREMENTS
);
arithmetic
(
&
mut
bencher
.with_name
(
"arithmetic"
));
random
(
&
mut
bencher
.with_name
(
"random"
));
...
...
This diff is collapsed.
Click to expand it.
examples/arithmetic.rs
+
6
−
5
View file @
3a515bf1
use
rand
::
Rng
;
fn
arithmetic
(
b
:
&
mut
plnk
::
Bencher
)
{
plnk
::
bench
(
b
,
"addition"
,
|
_
|
plnk
::
timeit
(||
1
+
2
));
plnk
::
bench
(
b
,
"substraction"
,
|
_
|
plnk
::
timeit
(||
1
-
2
));
plnk
::
bench
(
b
,
"multiplication"
,
|
_
|
plnk
::
timeit
(||
2
*
3
));
plnk
::
bench
(
b
,
"addition"
,
||
plnk
::
timeit
(||
1
+
2
));
plnk
::
bench
(
b
,
"substraction"
,
||
plnk
::
timeit
(||
1
-
2
));
plnk
::
bench
(
b
,
"multiplication"
,
||
plnk
::
timeit
(||
2
*
3
));
}
fn
random
(
b
:
&
mut
plnk
::
Bencher
)
{
plnk
::
bench
(
b
,
"sampling"
,
|
rng
|
plnk
::
timeit
(||
rng
.gen
::
<
u128
>
()));
let
mut
rng
=
rand
::
thread_rng
();
plnk
::
bench
(
b
,
"sampling"
,
||
plnk
::
timeit
(||
rng
.gen
::
<
u128
>
()));
}
fn
main
()
{
const
NB_MEASUREMENTS
:
usize
=
10
;
let
bencher
=
plnk
::
Bencher
::
new
(
NB_MEASUREMENTS
,
rand
::
thread_rng
()
);
let
bencher
=
plnk
::
Bencher
::
new
(
NB_MEASUREMENTS
);
arithmetic
(
&
mut
bencher
.with_name
(
"arithmetic"
));
random
(
&
mut
bencher
.with_name
(
"random"
));
...
...
This diff is collapsed.
Click to expand it.
examples/capture.rs
+
2
−
2
View file @
3a515bf1
fn
capture
(
b
:
&
mut
plnk
::
Bencher
)
{
let
outer
=
10
;
plnk
::
bench
(
b
,
"dummy"
,
|
_
|
{
plnk
::
bench
(
b
,
"dummy"
,
||
{
let
inner
=
outer
;
plnk
::
timeit
(||
inner
+
outer
)
});
...
...
@@ -8,7 +8,7 @@ fn capture(b: &mut plnk::Bencher) {
fn
main
()
{
const
NB_MEASUREMENTS
:
usize
=
10
;
let
bencher
=
plnk
::
Bencher
::
new
(
NB_MEASUREMENTS
,
rand
::
thread_rng
()
);
let
bencher
=
plnk
::
Bencher
::
new
(
NB_MEASUREMENTS
);
capture
(
&
mut
bencher
.with_name
(
"capture"
));
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
3
−
9
View file @
3a515bf1
...
...
@@ -2,24 +2,19 @@
use
std
::
time
::{
Duration
,
Instant
};
use
rand
::{
rngs
::
ThreadRng
,
RngCore
};
/// hold information about the benchmark to run
pub
struct
Bencher
{
/// the number of times each bench should run, the higher this number the lower the variance
nb_measurements
:
usize
,
/// the name of the benchmark
name
:
String
,
/// a random number generator
rng
:
ThreadRng
,
}
impl
Bencher
{
pub
fn
new
(
nb_measurements
:
usize
,
rng
:
ThreadRng
)
->
Self
{
pub
fn
new
(
nb_measurements
:
usize
)
->
Self
{
Self
{
nb_measurements
,
name
:
""
.to_string
(),
rng
,
}
}
...
...
@@ -28,7 +23,6 @@ impl Bencher {
Self
{
nb_measurements
:
self
.nb_measurements
,
name
:
name
.to_string
(),
rng
:
self
.rng
.clone
(),
}
}
}
...
...
@@ -41,7 +35,7 @@ impl Bencher {
/// - the measurements will be printed to STDOUT as JSON
pub
fn
bench
<
F
>
(
b
:
&
mut
Bencher
,
label
:
&
str
,
mut
thing
:
F
)
where
F
:
FnMut
(
&
mut
dyn
RngCore
)
->
Duration
,
F
:
FnMut
()
->
Duration
,
{
let
mut
times
=
vec!
[];
for
i
in
0
..
b
.nb_measurements
{
...
...
@@ -53,7 +47,7 @@ where
b
.nb_measurements
);
times
.push
(
thing
(
&
mut
b
.rng
)
.as_nanos
());
times
.push
(
thing
()
.as_nanos
());
}
eprintln!
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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