Add option to specify an output file for the benchmarking results

master
Trivernis 4 years ago
parent 842401043f
commit dd72c4af5c

@ -1,6 +1,6 @@
[package]
name = "benchlib-rs"
version = "0.3.1"
version = "0.3.2"
authors = ["Trivernis <trivernis@gmail.com>"]
edition = "2018"
license-file = "LICENSE"

@ -2,6 +2,8 @@ use std::time::{Duration, Instant};
use std::fmt::{self, Display};
use rayon::prelude::*;
use termion::{color, style};
use std::io::{BufWriter, Write};
use std::fs::File;
#[derive(Debug, Clone)]
pub struct BenchVec {
@ -127,6 +129,7 @@ pub struct Bencher {
iterations: usize,
max_auto_iterations: usize,
bench_duration: Duration,
writer: Option<BufWriter<File>>
}
impl Bencher {
@ -136,9 +139,11 @@ impl Bencher {
measurements: Vec::new(),
iterations: 100,
max_auto_iterations: 10000,
writer: None,
}
}
/// Calculates the time it takes to measure a benchmark
fn calculate_bench_duration() -> Duration{
let mut durations = BenchVec::new();
for _ in 0..1000 {
@ -204,6 +209,9 @@ impl Bencher {
}
}
println!("Result: {}", durations);
if let Some(writer) = &mut self.writer {
let _ = writer.write(format!("{}\t{:?}\t{:.2}ns\n", name, durations.average(), durations.standard_deviation()).as_bytes());
}
self.measurements.push(durations);
self
@ -233,4 +241,9 @@ impl Bencher {
self
}
/// Adds a file to write the output to
pub fn write_output_to(&mut self, writer: BufWriter<File>) {
self.writer = Some(writer);
}
}
Loading…
Cancel
Save