aboutsummaryrefslogtreecommitdiff
path: root/src/tests/example_mapping
diff options
context:
space:
mode:
authorAria Shrimpton <me@aria.rip>2024-02-27 09:41:29 +0000
committerAria Shrimpton <me@aria.rip>2024-02-27 09:41:29 +0000
commit4944cba55324d2dc603aa8e4c6832e0bf2a87147 (patch)
treeff831b54e5318f0b2a8a2b8ef5120f3d196954f7 /src/tests/example_mapping
parentfad685c53308f9fd7a449f23d5123ee56080e51b (diff)
add mapping example benchmark
Diffstat (limited to 'src/tests/example_mapping')
-rw-r--r--src/tests/example_mapping/Cargo.toml17
-rw-r--r--src/tests/example_mapping/benches/main.rs16
-rw-r--r--src/tests/example_mapping/src/lib.rs19
-rw-r--r--src/tests/example_mapping/src/types.pr.rs3
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*/