summaryrefslogtreecommitdiffstats
path: root/library/test/src/bench.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--library/test/src/bench.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/library/test/src/bench.rs b/library/test/src/bench.rs
index 7869ba2c0..23925e6ea 100644
--- a/library/test/src/bench.rs
+++ b/library/test/src/bench.rs
@@ -49,12 +49,12 @@ impl Bencher {
self.summary = Some(iter(&mut inner));
}
- pub fn bench<F>(&mut self, mut f: F) -> Option<stats::Summary>
+ pub fn bench<F>(&mut self, mut f: F) -> Result<Option<stats::Summary>, String>
where
- F: FnMut(&mut Bencher),
+ F: FnMut(&mut Bencher) -> Result<(), String>,
{
- f(self);
- self.summary
+ let result = f(self);
+ result.map(|_| self.summary)
}
}
@@ -195,7 +195,7 @@ pub fn benchmark<F>(
nocapture: bool,
f: F,
) where
- F: FnMut(&mut Bencher),
+ F: FnMut(&mut Bencher) -> Result<(), String>,
{
let mut bs = Bencher { mode: BenchMode::Auto, summary: None, bytes: 0 };
@@ -211,14 +211,14 @@ pub fn benchmark<F>(
let test_result = match result {
//bs.bench(f) {
- Ok(Some(ns_iter_summ)) => {
+ Ok(Ok(Some(ns_iter_summ))) => {
let ns_iter = cmp::max(ns_iter_summ.median as u64, 1);
let mb_s = bs.bytes * 1000 / ns_iter;
let bs = BenchSamples { ns_iter_summ, mb_s: mb_s as usize };
TestResult::TrBench(bs)
}
- Ok(None) => {
+ Ok(Ok(None)) => {
// iter not called, so no data.
// FIXME: error in this case?
let samples: &mut [f64] = &mut [0.0_f64; 1];
@@ -226,6 +226,7 @@ pub fn benchmark<F>(
TestResult::TrBench(bs)
}
Err(_) => TestResult::TrFailed,
+ Ok(Err(_)) => TestResult::TrFailed,
};
let stdout = data.lock().unwrap().to_vec();
@@ -233,10 +234,10 @@ pub fn benchmark<F>(
monitor_ch.send(message).unwrap();
}
-pub fn run_once<F>(f: F)
+pub fn run_once<F>(f: F) -> Result<(), String>
where
- F: FnMut(&mut Bencher),
+ F: FnMut(&mut Bencher) -> Result<(), String>,
{
let mut bs = Bencher { mode: BenchMode::Single, summary: None, bytes: 0 };
- bs.bench(f);
+ bs.bench(f).map(|_| ())
}