aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAria Shrimpton <me@aria.rip>2024-02-27 09:41:23 +0000
committerAria Shrimpton <me@aria.rip>2024-02-27 09:41:23 +0000
commitfad685c53308f9fd7a449f23d5123ee56080e51b (patch)
tree8e483e5caa380208320ecb05c14e32fc11f7c9a8 /src
parentabc050060403d0d41c1a7c4a5e29b8b26f6e5d1b (diff)
cleanup example_ benchmarks
Diffstat (limited to 'src')
-rw-r--r--src/tests/example_sets/benches/main.rs2
-rw-r--r--src/tests/example_sets/src/lib.rs5
-rw-r--r--src/tests/example_stack/Cargo.toml2
-rw-r--r--src/tests/example_stack/benches/do_stuff.rs10
-rw-r--r--src/tests/example_stack/benches/main.rs16
-rw-r--r--src/tests/example_stack/src/lib.rs18
-rw-r--r--src/tests/example_stack/src/types.pr.rs2
7 files changed, 34 insertions, 21 deletions
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<usize> = 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::<u32>::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<T> {
\c <: (Stack) -> (forall \x -> ((equal? (op-pop ((op-push c) x))) x))
}
-type StackCon<S> = {c impl (Container, Stack) | (lifo c)}
+type StackCon<S> = {c impl (Stack) | (lifo c)}
*ENDSPEC*/