per-sample option in bench
This commit is contained in:
parent
7cba467342
commit
76ea2abf85
|
@ -8,6 +8,8 @@ pub fn fetch(benchmark: &mut Benchmark) {
|
|||
// params
|
||||
const BLOCKS: usize = 1000;
|
||||
|
||||
benchmark.samples(BLOCKS);
|
||||
|
||||
// test setup
|
||||
let path = RandomTempPath::create_dir();
|
||||
let store = Storage::new(path.as_path()).unwrap();
|
||||
|
@ -49,6 +51,7 @@ pub fn fetch(benchmark: &mut Benchmark) {
|
|||
pub fn write(benchmark: &mut Benchmark) {
|
||||
// params
|
||||
const BLOCKS: usize = 1000;
|
||||
benchmark.samples(BLOCKS);
|
||||
|
||||
// setup
|
||||
let path = RandomTempPath::create_dir();
|
||||
|
@ -84,6 +87,7 @@ pub fn write(benchmark: &mut Benchmark) {
|
|||
pub fn reorg_short(benchmark: &mut Benchmark) {
|
||||
// params
|
||||
const BLOCKS: usize = 1000;
|
||||
benchmark.samples(BLOCKS);
|
||||
|
||||
// setup
|
||||
let path = RandomTempPath::create_dir();
|
||||
|
@ -166,6 +170,8 @@ pub fn write_heavy(benchmark: &mut Benchmark) {
|
|||
const BLOCKS: usize = 100;
|
||||
const TRANSACTIONS: usize = 100;
|
||||
|
||||
benchmark.samples(BLOCKS);
|
||||
|
||||
// test setup
|
||||
let path = RandomTempPath::create_dir();
|
||||
let store = Storage::new(path.as_path()).unwrap();
|
||||
|
|
|
@ -14,6 +14,7 @@ use std::str;
|
|||
pub struct Benchmark {
|
||||
start: Option<PreciseTime>,
|
||||
end: Option<PreciseTime>,
|
||||
samples: Option<usize>,
|
||||
}
|
||||
|
||||
impl Benchmark {
|
||||
|
@ -28,6 +29,10 @@ impl Benchmark {
|
|||
pub fn evaluate(&self) -> Duration {
|
||||
self.start.expect("benchmarch never ended").to(self.end.expect("benchmark never started"))
|
||||
}
|
||||
|
||||
pub fn samples(&mut self, samples: usize) {
|
||||
self.samples = Some(samples);
|
||||
}
|
||||
}
|
||||
|
||||
fn decimal_mark(s: String) -> String {
|
||||
|
@ -44,7 +49,14 @@ fn run_benchmark<F>(name: &str, f: F) where F: FnOnce(&mut Benchmark) {
|
|||
|
||||
let mut benchmark = Benchmark::default();
|
||||
f(&mut benchmark);
|
||||
if let Some(samples) = benchmark.samples {
|
||||
println!("{} ns/sample",
|
||||
decimal_mark(format!("{}", benchmark.evaluate().num_nanoseconds().unwrap() / samples as i64)),
|
||||
);
|
||||
}
|
||||
else {
|
||||
println!("{} ns", decimal_mark(format!("{}", benchmark.evaluate().num_nanoseconds().unwrap())));
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! benchmark {
|
||||
|
|
Loading…
Reference in New Issue