aboutsummaryrefslogtreecommitdiff
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
parentfad685c53308f9fd7a449f23d5123ee56080e51b (diff)
add mapping example benchmark
-rw-r--r--src/tests/Cargo.lock9
-rw-r--r--src/tests/Cargo.toml1
-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
6 files changed, 65 insertions, 0 deletions
diff --git a/src/tests/Cargo.lock b/src/tests/Cargo.lock
index 8c4d551..ddcef9f 100644
--- a/src/tests/Cargo.lock
+++ b/src/tests/Cargo.lock
@@ -188,6 +188,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
+name = "example_mapping"
+version = "0.1.0"
+dependencies = [
+ "criterion",
+ "primrose-library",
+ "rand",
+]
+
+[[package]]
name = "example_sets"
version = "0.1.0"
dependencies = [
diff --git a/src/tests/Cargo.toml b/src/tests/Cargo.toml
index 15e8d64..de68bbe 100644
--- a/src/tests/Cargo.toml
+++ b/src/tests/Cargo.toml
@@ -3,6 +3,7 @@ resolver = "2"
members = [
"example_sets",
"example_stack",
+ "example_mapping",
"aoc-2021-09",
"aoc-2022-08",
"aoc-2022-09",
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*/