@@ -285,6 +285,9 @@ pub struct TestOpts {
285
285
pub logfile : Option < Path > ,
286
286
pub nocapture : bool ,
287
287
pub color : ColorConfig ,
288
+ pub show_boxplot : bool ,
289
+ pub boxplot_width : uint ,
290
+ pub show_all_stats : bool ,
288
291
}
289
292
290
293
impl TestOpts {
@@ -302,6 +305,9 @@ impl TestOpts {
302
305
logfile : None ,
303
306
nocapture : false ,
304
307
color : AutoColor ,
308
+ show_boxplot : false ,
309
+ boxplot_width : 50 ,
310
+ show_all_stats : false ,
305
311
}
306
312
}
307
313
}
@@ -332,7 +338,10 @@ fn optgroups() -> Vec<getopts::OptGroup> {
332
338
getopts:: optopt( "" , "color" , "Configure coloring of output:
333
339
auto = colorize if stdout is a tty and tests are run on serially (default);
334
340
always = always colorize output;
335
- never = never colorize output;" , "auto|always|never" ) )
341
+ never = never colorize output;" , "auto|always|never" ) ,
342
+ getopts:: optflag( "" , "boxplot" , "Display a boxplot of the benchmark statistics" ) ,
343
+ getopts:: optopt( "" , "boxplot-width" , "Set the boxplot width (default 50)" , "WIDTH" ) ,
344
+ getopts:: optflag( "" , "stats" , "Display the benchmark min, max, and quartiles" ) )
336
345
}
337
346
338
347
fn usage ( binary : & str ) {
@@ -423,6 +432,21 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
423
432
v) ) ) ,
424
433
} ;
425
434
435
+ let show_boxplot = matches. opt_present ( "boxplot" ) ;
436
+ let boxplot_width = match matches. opt_str ( "boxplot-width" ) {
437
+ Some ( width) => {
438
+ match FromStr :: from_str ( width. as_slice ( ) ) {
439
+ Some ( width) => width,
440
+ None => {
441
+ return Some ( Err ( format ! ( "argument for --boxplot-width must be a uint" ) ) ) ;
442
+ }
443
+ }
444
+ }
445
+ None => 50 ,
446
+ } ;
447
+
448
+ let show_all_stats = matches. opt_present ( "stats" ) ;
449
+
426
450
let test_opts = TestOpts {
427
451
filter : filter,
428
452
run_ignored : run_ignored,
@@ -435,6 +459,9 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
435
459
logfile : logfile,
436
460
nocapture : nocapture,
437
461
color : color,
462
+ show_boxplot : show_boxplot,
463
+ boxplot_width : boxplot_width,
464
+ show_all_stats : show_all_stats,
438
465
} ;
439
466
440
467
Some ( Ok ( test_opts) )
@@ -485,6 +512,9 @@ struct ConsoleTestState<T> {
485
512
log_out : Option < File > ,
486
513
out : OutputLocation < T > ,
487
514
use_color : bool ,
515
+ show_boxplot : bool ,
516
+ boxplot_width : uint ,
517
+ show_all_stats : bool ,
488
518
total : uint ,
489
519
passed : uint ,
490
520
failed : uint ,
@@ -511,6 +541,9 @@ impl<T: Writer> ConsoleTestState<T> {
511
541
out : out,
512
542
log_out : log_out,
513
543
use_color : use_color ( opts) ,
544
+ show_boxplot : opts. show_boxplot ,
545
+ boxplot_width : opts. boxplot_width ,
546
+ show_all_stats : opts. show_all_stats ,
514
547
total : 0 u,
515
548
passed : 0 u,
516
549
failed : 0 u,
@@ -606,8 +639,31 @@ impl<T: Writer> ConsoleTestState<T> {
606
639
}
607
640
TrBench ( ref bs) => {
608
641
try!( self . write_bench ( ) ) ;
609
- self . write_plain ( format ! ( ": {}" ,
610
- fmt_bench_samples( bs) ) . as_slice ( ) )
642
+
643
+ if self . show_boxplot {
644
+ let mut wr = Vec :: new ( ) ;
645
+
646
+ try!( stats:: write_boxplot ( & mut wr, & bs. ns_iter_summ , self . boxplot_width ) ) ;
647
+
648
+ let s = String :: from_utf8 ( wr) . unwrap ( ) ;
649
+
650
+ try!( self . write_plain ( format ! ( ": {}" , s) . as_slice ( ) ) ) ;
651
+ }
652
+
653
+ if self . show_all_stats {
654
+ let mut wr = Vec :: new ( ) ;
655
+
656
+ try!( stats:: write_5_number_summary ( & mut wr, & bs. ns_iter_summ ) ) ;
657
+
658
+ let s = String :: from_utf8 ( wr) . unwrap ( ) ;
659
+
660
+ try!( self . write_plain ( format ! ( ": {}" , s) . as_slice ( ) ) ) ;
661
+ } else {
662
+ try!( self . write_plain ( format ! ( ": {}" ,
663
+ fmt_bench_samples( bs) ) . as_slice ( ) ) ) ;
664
+ }
665
+
666
+ Ok ( ( ) )
611
667
}
612
668
} ) ;
613
669
self . write_plain ( "\n " )
@@ -680,14 +736,14 @@ impl<T: Writer> ConsoleTestState<T> {
680
736
}
681
737
Improvement ( pct) => {
682
738
improved += 1 ;
683
- try!( self . write_plain ( format ! ( ": {}" , * k) . as_slice ( ) ) ) ;
739
+ try!( self . write_plain ( format ! ( ": {} " , * k) . as_slice ( ) ) ) ;
684
740
try!( self . write_improved ( ) ) ;
685
741
try!( self . write_plain ( format ! ( " by {:.2}%\n " ,
686
742
pct as f64 ) . as_slice ( ) ) ) ;
687
743
}
688
744
Regression ( pct) => {
689
745
regressed += 1 ;
690
- try!( self . write_plain ( format ! ( ": {}" , * k) . as_slice ( ) ) ) ;
746
+ try!( self . write_plain ( format ! ( ": {} " , * k) . as_slice ( ) ) ) ;
691
747
try!( self . write_regressed ( ) ) ;
692
748
try!( self . write_plain ( format ! ( " by {:.2}%\n " ,
693
749
pct as f64 ) . as_slice ( ) ) ) ;
@@ -859,6 +915,9 @@ fn should_sort_failures_before_printing_them() {
859
915
log_out : None ,
860
916
out : Raw ( Vec :: new ( ) ) ,
861
917
use_color : false ,
918
+ show_boxplot : false ,
919
+ boxplot_width : 0 ,
920
+ show_all_stats : false ,
862
921
total : 0 u,
863
922
passed : 0 u,
864
923
failed : 0 u,
0 commit comments