From 4944cba55324d2dc603aa8e4c6832e0bf2a87147 Mon Sep 17 00:00:00 2001 From: Aria Shrimpton Date: Tue, 27 Feb 2024 09:41:29 +0000 Subject: add mapping example benchmark --- src/tests/example_mapping/Cargo.toml | 17 +++++++++++++++++ src/tests/example_mapping/benches/main.rs | 16 ++++++++++++++++ src/tests/example_mapping/src/lib.rs | 19 +++++++++++++++++++ src/tests/example_mapping/src/types.pr.rs | 3 +++ 4 files changed, 55 insertions(+) create mode 100644 src/tests/example_mapping/Cargo.toml create mode 100644 src/tests/example_mapping/benches/main.rs create mode 100644 src/tests/example_mapping/src/lib.rs create mode 100644 src/tests/example_mapping/src/types.pr.rs (limited to 'src/tests/example_mapping') 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 = 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 = {c impl (Mapping) | true} +*ENDSPEC*/ -- cgit v1.2.3