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
f6592326
Verified
Commit
f6592326
authored
4 months ago
by
STEVAN Antoine
Browse files
Options
Downloads
Patches
Plain Diff
add `bench`, `bench_multiple` and `bench_and_return`
parent
15ab26aa
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#9107
passed
4 months ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/arithmetic.rs
+1
-1
1 addition, 1 deletion
examples/arithmetic.rs
src/lib.rs
+19
-10
19 additions, 10 deletions
src/lib.rs
with
20 additions
and
11 deletions
examples/arithmetic.rs
+
1
−
1
View file @
f6592326
...
...
@@ -2,7 +2,7 @@ use clap::Parser;
use
rand
::
Rng
;
fn
arithmetic
(
b
:
&
plnk
::
Bencher
)
{
let
res
=
b
.bench_multiple
(
vec!
[
let
res
=
b
.bench_multiple
_and_return
(
vec!
[
(
plnk
::
label!
{
operation
:
"addition"
}
.to_string
(),
plnk
::
closure!
{
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
19
−
10
View file @
f6592326
...
...
@@ -113,7 +113,7 @@ impl Bencher {
/// - the measurements will be printed to STDOUT or to file as JSON
/// - the result of the last run will be returned
#[allow(clippy::type_complexity)]
pub
fn
bench_multiple
<
O
>
(
pub
fn
bench_multiple
_and_return
<
O
>
(
&
self
,
benches
:
Vec
<
(
String
,
Box
<
dyn
Fn
()
->
(
Duration
,
O
)
>
)
>
,
)
->
Option
<
O
>
{
...
...
@@ -155,15 +155,24 @@ impl Bencher {
res
}
/// benchmark a piece of code
///
/// - label: an additional label to differentiate similar but different things to benchmark in the
/// same bencher
/// - f: the piece of code to run and measure
/// - the measurements will be printed to STDOUT or to file as JSON
/// - the result of the last run will be returned
pub
fn
bench
<
O
>
(
&
self
,
label
:
impl
ToString
,
f
:
Box
<
dyn
Fn
()
->
(
Duration
,
O
)
>
)
->
Option
<
O
>
{
self
.bench_multiple
(
vec!
[(
label
.to_string
(),
f
)])
/// see [`Self::bench_multiple_and_return`]
#[allow(clippy::type_complexity)]
pub
fn
bench_multiple
<
O
>
(
&
self
,
benches
:
Vec
<
(
String
,
Box
<
dyn
Fn
()
->
(
Duration
,
O
)
>
)
>
)
{
self
.bench_multiple_and_return
(
benches
);
}
/// see [`Self::bench_multiple_and_return`]
pub
fn
bench_and_return
<
O
>
(
&
self
,
label
:
impl
ToString
,
f
:
Box
<
dyn
Fn
()
->
(
Duration
,
O
)
>
,
)
->
Option
<
O
>
{
self
.bench_multiple_and_return
(
vec!
[(
label
.to_string
(),
f
)])
}
/// see [`Self::bench_multiple_and_return`]
pub
fn
bench
<
O
>
(
&
self
,
label
:
impl
ToString
,
f
:
Box
<
dyn
Fn
()
->
(
Duration
,
O
)
>
)
{
self
.bench_multiple_and_return
(
vec!
[(
label
.to_string
(),
f
)]);
}
}
...
...
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