diff options
Diffstat (limited to 'src/tests/example_mapping')
-rw-r--r-- | src/tests/example_mapping/Cargo.toml | 17 | ||||
-rw-r--r-- | src/tests/example_mapping/benches/main.rs | 16 | ||||
-rw-r--r-- | src/tests/example_mapping/src/lib.rs | 19 | ||||
-rw-r--r-- | src/tests/example_mapping/src/types.pr.rs | 3 |
4 files changed, 55 insertions, 0 deletions
diff --git a/src/tests/example_mapping/Cargo.toml b/src/tests/example_mapping/Cargo.toml new file mode 100644 index 0000000..94756ea --- /dev/null +++ b/src/tests/example_mapping/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "example_mapping" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +primrose-library = { path = "../../crates/library" } +rand = { workspace = true } + +[dev-dependencies] +criterion = { workspace = true } + +[[bench]] +name = "main" +harness = false diff --git a/src/tests/example_mapping/benches/main.rs b/src/tests/example_mapping/benches/main.rs new file mode 100644 index 0000000..e681a68 --- /dev/null +++ b/src/tests/example_mapping/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_mapping-insert_get", size), + size, + |b, &n| { + b.iter(|| example_mapping::insert_get(n)); + }, + ); + } +} + +criterion_group!(benches, run_benches); +criterion_main!(benches); diff --git a/src/tests/example_mapping/src/lib.rs b/src/tests/example_mapping/src/lib.rs new file mode 100644 index 0000000..335c55c --- /dev/null +++ b/src/tests/example_mapping/src/lib.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] +mod types; + +use primrose_library::traits::Mapping; +use rand::random; +use std::hint::black_box; +use types::*; + +pub fn insert_get(n: usize) { + let mut set: Map<String, usize> = Map::default(); + + for i in 0..n { + set.insert(i.to_string(), random()); + } + + for i in 0..n * n { + black_box(|x| x)(black_box(set.get(&i.to_string()))); + } +} diff --git a/src/tests/example_mapping/src/types.pr.rs b/src/tests/example_mapping/src/types.pr.rs new file mode 100644 index 0000000..d85a0af --- /dev/null +++ b/src/tests/example_mapping/src/types.pr.rs @@ -0,0 +1,3 @@ +/*SPEC* +type Map<K, V> = {c impl (Mapping) | true} +*ENDSPEC*/ |