From fad685c53308f9fd7a449f23d5123ee56080e51b Mon Sep 17 00:00:00 2001 From: Aria Shrimpton Date: Tue, 27 Feb 2024 09:41:23 +0000 Subject: cleanup example_ benchmarks --- src/tests/example_sets/benches/main.rs | 2 +- src/tests/example_sets/src/lib.rs | 5 +++++ src/tests/example_stack/Cargo.toml | 2 +- src/tests/example_stack/benches/do_stuff.rs | 10 ---------- src/tests/example_stack/benches/main.rs | 16 ++++++++++++++++ src/tests/example_stack/src/lib.rs | 18 ++++++++++-------- src/tests/example_stack/src/types.pr.rs | 2 +- 7 files changed, 34 insertions(+), 21 deletions(-) delete mode 100644 src/tests/example_stack/benches/do_stuff.rs create mode 100644 src/tests/example_stack/benches/main.rs (limited to 'src') diff --git a/src/tests/example_sets/benches/main.rs b/src/tests/example_sets/benches/main.rs index 3092cdf..7b46c8e 100644 --- a/src/tests/example_sets/benches/main.rs +++ b/src/tests/example_sets/benches/main.rs @@ -1,7 +1,7 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; fn run_benches(c: &mut Criterion) { - for size in [10, 500, 10_000, 50_000].iter() { + for size in [500, 10_000, 50_000].iter() { c.bench_with_input( BenchmarkId::new("example_sets-insert_n", size), size, diff --git a/src/tests/example_sets/src/lib.rs b/src/tests/example_sets/src/lib.rs index 14670cf..8e6caa5 100644 --- a/src/tests/example_sets/src/lib.rs +++ b/src/tests/example_sets/src/lib.rs @@ -5,6 +5,7 @@ use types::Set; use primrose_library::traits::*; use rand::random; +use std::hint::black_box; pub fn insert_n(n: usize) { let mut set: Set = Set::default(); @@ -12,4 +13,8 @@ pub fn insert_n(n: usize) { for _ in 0..n { set.insert(random()); } + + for i in 0..n * n { + black_box(|x| x)(black_box(set.contains(&i))); + } } diff --git a/src/tests/example_stack/Cargo.toml b/src/tests/example_stack/Cargo.toml index 55e4338..7207622 100644 --- a/src/tests/example_stack/Cargo.toml +++ b/src/tests/example_stack/Cargo.toml @@ -12,5 +12,5 @@ primrose-library = { path = "../../crates/library" } criterion = { workspace = true } [[bench]] -name = "do_stuff" +name = "main" harness = false diff --git a/src/tests/example_stack/benches/do_stuff.rs b/src/tests/example_stack/benches/do_stuff.rs deleted file mode 100644 index 91f21fb..0000000 --- a/src/tests/example_stack/benches/do_stuff.rs +++ /dev/null @@ -1,10 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; - -fn run_benches(c: &mut Criterion) { - c.bench_function("example_stack-do_something", |b| { - b.iter(|| example_stack::do_something()) - }); -} - -criterion_group!(benches, run_benches); -criterion_main!(benches); diff --git a/src/tests/example_stack/benches/main.rs b/src/tests/example_stack/benches/main.rs new file mode 100644 index 0000000..575d045 --- /dev/null +++ b/src/tests/example_stack/benches/main.rs @@ -0,0 +1,16 @@ +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; + +fn run_benches(c: &mut Criterion) { + for size in [500, 10_000, 50_000].iter() { + c.bench_with_input( + BenchmarkId::new("example_stack-push_pop", size), + size, + |b, &n| { + b.iter(|| example_stack::push_pop(n)); + }, + ); + } +} + +criterion_group!(benches, run_benches); +criterion_main!(benches); diff --git a/src/tests/example_stack/src/lib.rs b/src/tests/example_stack/src/lib.rs index 086dd6a..8ddaf92 100644 --- a/src/tests/example_stack/src/lib.rs +++ b/src/tests/example_stack/src/lib.rs @@ -1,14 +1,16 @@ #![feature(type_alias_impl_trait)] mod types; -use primrose_library::traits::Container; + +use primrose_library::traits::Stack; +use std::hint::black_box; use types::*; -pub fn do_something() { - let mut c = StackCon::::default(); - for x in 0..10 { - c.insert(x); - c.insert(x); - //c.first(); +pub fn push_pop(n: usize) { + let mut c = StackCon::default(); + for x in 0..n { + c.push(x); + } + for _ in 0..n { + black_box(|x| x)(c.pop()); } - assert_eq!(c.len(), 20); } diff --git a/src/tests/example_stack/src/types.pr.rs b/src/tests/example_stack/src/types.pr.rs index c45bb34..38fac79 100644 --- a/src/tests/example_stack/src/types.pr.rs +++ b/src/tests/example_stack/src/types.pr.rs @@ -3,5 +3,5 @@ property lifo { \c <: (Stack) -> (forall \x -> ((equal? (op-pop ((op-push c) x))) x)) } -type StackCon = {c impl (Container, Stack) | (lifo c)} +type StackCon = {c impl (Stack) | (lifo c)} *ENDSPEC*/ -- cgit v1.2.3