aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAria Shrimpton <me@aria.rip>2024-03-19 22:38:59 +0000
committerAria Shrimpton <me@aria.rip>2024-03-19 22:38:59 +0000
commit18be480e89e773f827da930d98618db4a9c9d9f9 (patch)
tree1ec5ed902a9e40b136c0e8f3d59d241816e719c5 /src
parent05715322ad643b39234e0d2f752acc762e760b35 (diff)
benchmark updates
Diffstat (limited to 'src')
-rw-r--r--src/tests/example_mapping/benches/main.rs6
-rw-r--r--src/tests/example_mapping/src/lib.rs12
-rw-r--r--src/tests/example_sets/benches/main.rs6
-rw-r--r--src/tests/example_sets/src/lib.rs8
-rw-r--r--src/tests/example_stack/benches/main.rs2
-rw-r--r--src/tests/prime_sieve/benches/main.rs2
6 files changed, 20 insertions, 16 deletions
diff --git a/src/tests/example_mapping/benches/main.rs b/src/tests/example_mapping/benches/main.rs
index 04d43fb..77b2394 100644
--- a/src/tests/example_mapping/benches/main.rs
+++ b/src/tests/example_mapping/benches/main.rs
@@ -1,12 +1,14 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
+use rand::{rngs::StdRng, SeedableRng};
fn run_benches(c: &mut Criterion) {
- for size in [10_000, 30_000, 60_000].iter() {
+ let mut rng = StdRng::seed_from_u64(42);
+ for size in [50, 150, 2_500, 7_500].iter() {
c.bench_with_input(
BenchmarkId::new("example_mapping-insert_get", size),
size,
|b, &n| {
- b.iter(|| example_mapping::insert_get(n));
+ b.iter(|| example_mapping::insert_get(&mut rng, n));
},
);
}
diff --git a/src/tests/example_mapping/src/lib.rs b/src/tests/example_mapping/src/lib.rs
index f9216df..c95a016 100644
--- a/src/tests/example_mapping/src/lib.rs
+++ b/src/tests/example_mapping/src/lib.rs
@@ -2,18 +2,18 @@
mod types;
use primrose_library::traits::Mapping;
-use rand::random;
+use rand::{rngs::StdRng, Rng};
use std::hint::black_box;
use types::*;
-pub fn insert_get(n: usize) {
- let mut set: Map<String, usize> = Map::default();
+pub fn insert_get(rng: &mut StdRng, n: usize) {
+ let mut set: Map<usize, usize> = Map::default();
- for i in 0..n {
- set.insert(i.to_string(), random());
+ for _ in 0..n {
+ set.insert(rng.gen(), rng.gen());
}
for i in 0..2 * n {
- black_box(|x| x)(black_box(set.get(&i.to_string())));
+ black_box(|x| x)(black_box(set.get(&i)));
}
}
diff --git a/src/tests/example_sets/benches/main.rs b/src/tests/example_sets/benches/main.rs
index 26e8547..03ab904 100644
--- a/src/tests/example_sets/benches/main.rs
+++ b/src/tests/example_sets/benches/main.rs
@@ -1,12 +1,14 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
+use rand::{rngs::StdRng, SeedableRng};
fn run_benches(c: &mut Criterion) {
- for size in [500, 2_000, 10_000, 50_000].iter() {
+ let mut rng = StdRng::seed_from_u64(42);
+ for size in [50, 150, 2_500, 7_500].iter() {
c.bench_with_input(
BenchmarkId::new("example_sets-insert_n", size),
size,
|b, &n| {
- b.iter(|| example_sets::insert_n(n));
+ b.iter(|| example_sets::insert_n(&mut rng, n));
},
);
}
diff --git a/src/tests/example_sets/src/lib.rs b/src/tests/example_sets/src/lib.rs
index c5bd163..5acd6d7 100644
--- a/src/tests/example_sets/src/lib.rs
+++ b/src/tests/example_sets/src/lib.rs
@@ -4,17 +4,17 @@ mod types;
use types::Set;
use primrose_library::traits::*;
-use rand::random;
+use rand::{rngs::StdRng, Rng};
use std::hint::black_box;
-pub fn insert_n(n: usize) {
+pub fn insert_n(rng: &mut StdRng, n: usize) {
let mut set: Set<usize> = Set::default();
for _ in 0..n {
- set.insert(random());
+ set.insert(rng.gen());
}
for _ in 0..2 * n {
- black_box(|x| x)(black_box(set.contains(&random())));
+ black_box(|x| x)(black_box(set.contains(&rng.gen())));
}
}
diff --git a/src/tests/example_stack/benches/main.rs b/src/tests/example_stack/benches/main.rs
index 5b6076b..2fb6dd3 100644
--- a/src/tests/example_stack/benches/main.rs
+++ b/src/tests/example_stack/benches/main.rs
@@ -1,7 +1,7 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
fn run_benches(c: &mut Criterion) {
- for size in [1_000_000, 10_000_000, 50_000_000].iter() {
+ for size in [10, 1000, 10_000].iter() {
c.bench_with_input(
BenchmarkId::new("example_stack-push_pop", size),
size,
diff --git a/src/tests/prime_sieve/benches/main.rs b/src/tests/prime_sieve/benches/main.rs
index 9b1b8c2..e4a4278 100644
--- a/src/tests/prime_sieve/benches/main.rs
+++ b/src/tests/prime_sieve/benches/main.rs
@@ -3,7 +3,7 @@ use criterion::Criterion;
use criterion::{criterion_group, criterion_main};
fn bench_sieve(c: &mut Criterion) {
- for size in [500, 20_000, 50_000].iter() {
+ for size in [50, 500, 50_000].iter() {
c.bench_with_input(BenchmarkId::new("prime_sieve", size), size, |b, &n| {
b.iter(|| prime_sieve::prime_sieve(n));
});