diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/Cargo.toml | 5 | ||||
-rw-r--r-- | src/tests/example_stack/Cargo.toml | 5 | ||||
-rw-r--r-- | src/tests/example_stack/benches/do_stuff.rs | 12 |
3 files changed, 15 insertions, 7 deletions
diff --git a/src/tests/Cargo.toml b/src/tests/Cargo.toml index d4d9ab2..b40694f 100644 --- a/src/tests/Cargo.toml +++ b/src/tests/Cargo.toml @@ -2,4 +2,7 @@ resolver = "2" members = [ "example_stack", -]
\ No newline at end of file +] + +[workspace.dependencies] +criterion = "0.3" diff --git a/src/tests/example_stack/Cargo.toml b/src/tests/example_stack/Cargo.toml index 3e3e617..55e4338 100644 --- a/src/tests/example_stack/Cargo.toml +++ b/src/tests/example_stack/Cargo.toml @@ -8,6 +8,9 @@ edition = "2021" [dependencies] primrose-library = { path = "../../crates/library" } +[dev-dependencies] +criterion = { workspace = true } + [[bench]] name = "do_stuff" -harness = false
\ No newline at end of file +harness = false diff --git a/src/tests/example_stack/benches/do_stuff.rs b/src/tests/example_stack/benches/do_stuff.rs index 69d50d5..c7e2e23 100644 --- a/src/tests/example_stack/benches/do_stuff.rs +++ b/src/tests/example_stack/benches/do_stuff.rs @@ -1,6 +1,8 @@ -fn main() { - // TODO: some actual benchmarking, not just a random loop - for _ in 0..20 { - example_stack::do_something(); - } +use criterion::{criterion_group, criterion_main, Criterion}; + +fn run_benches(c: &mut Criterion) { + c.bench_function("do_something", |b| b.iter(|| example_stack::do_something())); } + +criterion_group!(benches, run_benches); +criterion_main!(benches); |