Skip to content

Commit 07c12c7

Browse files
committed
test: expose error bars and the extra stats test keeps track of
1 parent d9c7c00 commit 07c12c7

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

src/libtest/lib.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ pub struct TestOpts {
286286
pub logfile: Option<Path>,
287287
pub nocapture: bool,
288288
pub color: ColorConfig,
289+
pub show_error_bar: bool,
290+
pub show_all_stats: bool,
289291
}
290292

291293
impl TestOpts {
@@ -303,6 +305,8 @@ impl TestOpts {
303305
logfile: None,
304306
nocapture: false,
305307
color: AutoColor,
308+
show_error_bar: false,
309+
show_all_stats: false,
306310
}
307311
}
308312
}
@@ -333,7 +337,9 @@ fn optgroups() -> Vec<getopts::OptGroup> {
333337
getopts::optopt("", "color", "Configure coloring of output:
334338
auto = colorize if stdout is a tty and tests are run on serially (default);
335339
always = always colorize output;
336-
never = never colorize output;", "auto|always|never"))
340+
never = never colorize output;", "auto|always|never"),
341+
getopts::optflag("", "error-bar", "Display error bars for the benchmarks"),
342+
getopts::optflag("", "stats", "Display the benchmark min, max, and quartiles"))
337343
}
338344

339345
fn usage(binary: &str) {
@@ -424,6 +430,9 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
424430
v))),
425431
};
426432

433+
let show_error_bar = matches.opt_present("error-bar");
434+
let show_all_stats = matches.opt_present("stats");
435+
427436
let test_opts = TestOpts {
428437
filter: filter,
429438
run_ignored: run_ignored,
@@ -436,6 +445,8 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
436445
logfile: logfile,
437446
nocapture: nocapture,
438447
color: color,
448+
show_error_bar: show_error_bar,
449+
show_all_stats: show_all_stats,
439450
};
440451

441452
Some(Ok(test_opts))
@@ -486,6 +497,8 @@ struct ConsoleTestState<T> {
486497
log_out: Option<File>,
487498
out: OutputLocation<T>,
488499
use_color: bool,
500+
show_error_bar: bool,
501+
show_all_stats: bool,
489502
total: uint,
490503
passed: uint,
491504
failed: uint,
@@ -512,6 +525,8 @@ impl<T: Writer> ConsoleTestState<T> {
512525
out: out,
513526
log_out: log_out,
514527
use_color: use_color(opts),
528+
show_error_bar: opts.show_error_bar,
529+
show_all_stats: opts.show_all_stats,
515530
total: 0u,
516531
passed: 0u,
517532
failed: 0u,
@@ -607,8 +622,31 @@ impl<T: Writer> ConsoleTestState<T> {
607622
}
608623
TrBench(ref bs) => {
609624
try!(self.write_bench());
610-
self.write_plain(format!(": {}",
611-
fmt_bench_samples(bs)).as_slice())
625+
626+
if self.show_error_bar {
627+
let mut wr = Vec::new();
628+
629+
try!(stats::write_boxplot(&mut wr, &bs.ns_iter_summ, 50));
630+
631+
let s = String::from_utf8(wr).unwrap();
632+
633+
try!(self.write_plain(format!(": {}", s).as_slice()));
634+
}
635+
636+
if self.show_all_stats {
637+
let mut wr = Vec::new();
638+
639+
try!(stats::write_5_number_summary(&mut wr, &bs.ns_iter_summ));
640+
641+
let s = String::from_utf8(wr).unwrap();
642+
643+
try!(self.write_plain(format!(": {}", s).as_slice()));
644+
} else {
645+
try!(self.write_plain(format!(": {}",
646+
fmt_bench_samples(bs)).as_slice()));
647+
}
648+
649+
Ok(())
612650
}
613651
});
614652
self.write_plain("\n")

src/libtest/stats.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ pub fn winsorize<T: Float + FromPrimitive>(samples: &mut [T], pct: T) {
331331
}
332332

333333
/// Render writes the min, max and quartiles of the provided `Summary` to the provided `Writer`.
334-
pub fn write_5_number_summary<T: Float + Show>(w: &mut io::Writer,
335-
s: &Summary<T>) -> io::IoResult<()> {
334+
pub fn write_5_number_summary<W: Writer, T: Float + Show>(w: &mut W,
335+
s: &Summary<T>) -> io::IoResult<()> {
336336
let (q1,q2,q3) = s.quartiles;
337337
write!(w, "(min={}, q1={}, med={}, q3={}, max={})",
338338
s.min,
@@ -353,8 +353,8 @@ pub fn write_5_number_summary<T: Float + Show>(w: &mut io::Writer,
353353
/// ```{.ignore}
354354
/// 10 | [--****#******----------] | 40
355355
/// ```
356-
pub fn write_boxplot<T: Float + Show + FromPrimitive>(
357-
w: &mut io::Writer,
356+
pub fn write_boxplot<W: Writer, T: Float + Show + FromPrimitive>(
357+
w: &mut W,
358358
s: &Summary<T>,
359359
width_hint: uint)
360360
-> io::IoResult<()> {

0 commit comments

Comments
 (0)