-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split bench_all_impl into multiple individual benches
- Loading branch information
1 parent
5bc9d1c
commit 6976d81
Showing
9 changed files
with
125 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
implementations/q146_lru_cache/benches/bench_intrusive_two_hashmaps.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mod modules; | ||
|
||
use criterion::{criterion_group, criterion_main}; | ||
|
||
use q146_lru_cache::impl_v4::LRUCache; | ||
|
||
bench_lru_cache!(q146_with_intrusive_two_hashmaps, LRUCache); | ||
|
||
criterion_group!(benches, q146_with_intrusive_two_hashmaps); | ||
criterion_main!(benches); |
10 changes: 10 additions & 0 deletions
10
implementations/q146_lru_cache/benches/bench_priority_queue.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mod modules; | ||
|
||
use criterion::{criterion_group, criterion_main}; | ||
|
||
use q146_lru_cache::impl_v1::LRUCache; | ||
|
||
bench_lru_cache!(q146_with_priority_queue, LRUCache); | ||
|
||
criterion_group!(benches, q146_with_priority_queue); | ||
criterion_main!(benches); |
10 changes: 10 additions & 0 deletions
10
implementations/q146_lru_cache/benches/bench_two_hashmaps.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mod modules; | ||
|
||
use criterion::{criterion_group, criterion_main}; | ||
|
||
use q146_lru_cache::impl_v3::LRUCache; | ||
|
||
bench_lru_cache!(q146_with_two_hashmaps, LRUCache); | ||
|
||
criterion_group!(benches, q146_with_two_hashmaps); | ||
criterion_main!(benches); |
10 changes: 10 additions & 0 deletions
10
implementations/q146_lru_cache/benches/bench_vec_hashmap.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mod modules; | ||
|
||
use criterion::{criterion_group, criterion_main}; | ||
|
||
use q146_lru_cache::impl_v2::LRUCache; | ||
|
||
bench_lru_cache!(q146_with_vec_hashmap, LRUCache); | ||
|
||
criterion_group!(benches, q146_with_vec_hashmap); | ||
criterion_main!(benches); |
66 changes: 66 additions & 0 deletions
66
implementations/q146_lru_cache/benches/modules/bench_common.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use std::ops::RangeInclusive; | ||
|
||
use once_cell::sync::Lazy; | ||
use rand::rngs::StdRng; | ||
use rand::{Rng, SeedableRng}; | ||
|
||
const SEED: u64 = 12345; // Use a fixed seed for reproducibility | ||
|
||
const NUM_OPERATIONS: usize = 10_000; | ||
|
||
fn key_range() -> RangeInclusive<i32> { | ||
0..=100_000 | ||
} | ||
|
||
fn value_range() -> RangeInclusive<i32> { | ||
0..=1_000_000_000 | ||
} | ||
|
||
pub static OPERATIONS: Lazy<Vec<(u8, i32, i32)>> = Lazy::new(|| { | ||
// Generate random data here | ||
let mut rng = StdRng::seed_from_u64(SEED); | ||
|
||
let mut operations = Vec::with_capacity(NUM_OPERATIONS); | ||
|
||
for _ in 0..NUM_OPERATIONS { | ||
let op = rng.gen_range(0..2) as u8; // 0 for put, 1 for get | ||
let key = rng.gen_range(key_range()); | ||
let value = rng.gen_range(value_range()); // Only needed for put operations | ||
operations.push((op, key, value)); | ||
} | ||
|
||
operations | ||
}); | ||
|
||
#[macro_export] | ||
macro_rules! bench_lru_cache { | ||
($bench_name:ident, $cache_type:ty) => { | ||
fn $bench_name(c: &mut ::criterion::Criterion) { | ||
// Define the capacity as a constant or parameter | ||
const CAPACITY: i32 = 3_000i32; | ||
|
||
c.bench_function(stringify!($bench_name), |b| { | ||
b.iter(|| { | ||
let mut cache: $cache_type = | ||
<$cache_type>::new(::criterion::black_box(CAPACITY)); | ||
for &(op, key, value) in $crate::modules::bench_common::OPERATIONS.iter() { | ||
match op { | ||
0 => { | ||
// Put operation | ||
cache.put( | ||
::criterion::black_box(key), | ||
::criterion::black_box(value), | ||
); | ||
} | ||
1 => { | ||
// Get operation | ||
::criterion::black_box(cache.get(::criterion::black_box(key))); | ||
} | ||
_ => unreachable!(), | ||
} | ||
} | ||
}) | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod bench_common; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e # Exit on error | ||
cargo clean | ||
find . -type f \( -name "*.profraw" -o -name "lcov*.info" \) -exec rm {} \; |