@@ -20,15 +20,16 @@ static COMPARISON_COLORS: [RGBColor; NUM_COLORS] = [
2020 RGBColor ( 0 , 255 , 127 ) ,
2121] ;
2222
23- pub fn line_comparison (
23+ pub ( crate ) fn line_comparison (
24+ line_cfg : LinePlotConfig ,
2425 formatter : & dyn ValueFormatter ,
2526 title : & str ,
2627 all_curves : & [ & ( & BenchmarkId , Vec < f64 > ) ] ,
2728 path : & Path ,
2829 value_type : ValueType ,
2930 axis_scale : AxisScale ,
3031) {
31- let ( unit, series_data) = line_comparison_series_data ( formatter, all_curves) ;
32+ let ( unit, series_data) = line_comparison_series_data ( line_cfg , formatter, all_curves) ;
3233
3334 let x_range =
3435 plotters:: data:: fitting_range ( series_data. iter ( ) . flat_map ( |( _, xs, _) | xs. iter ( ) ) ) ;
@@ -40,10 +41,17 @@ pub fn line_comparison(
4041 . unwrap ( ) ;
4142
4243 match axis_scale {
43- AxisScale :: Linear => {
44- draw_line_comarision_figure ( root_area, unit, x_range, y_range, value_type, series_data) ;
45- }
46- AxisScale :: Logarithmic => draw_line_comarision_figure (
44+ AxisScale :: Linear => draw_line_comparison_figure (
45+ line_cfg,
46+ root_area,
47+ unit,
48+ x_range,
49+ y_range,
50+ value_type,
51+ series_data,
52+ ) ,
53+ AxisScale :: Logarithmic => draw_line_comparison_figure (
54+ line_cfg,
4755 root_area,
4856 unit,
4957 x_range. log_scale ( ) ,
@@ -54,7 +62,8 @@ pub fn line_comparison(
5462 }
5563}
5664
57- fn draw_line_comarision_figure < XR : AsRangedCoord < Value = f64 > , YR : AsRangedCoord < Value = f64 > > (
65+ fn draw_line_comparison_figure < XR : AsRangedCoord < Value = f64 > , YR : AsRangedCoord < Value = f64 > > (
66+ line_cfg : LinePlotConfig ,
5867 root_area : DrawingArea < SVGBackend , Shift > ,
5968 y_unit : & str ,
6069 x_range : XR ,
@@ -83,7 +92,7 @@ fn draw_line_comarision_figure<XR: AsRangedCoord<Value = f64>, YR: AsRangedCoord
8392 . configure_mesh ( )
8493 . disable_mesh ( )
8594 . x_desc ( format ! ( "Input{}" , input_suffix) )
86- . y_desc ( format ! ( "Average time ({})" , y_unit) )
95+ . y_desc ( format ! ( "Average {} ({})" , line_cfg . label , y_unit) )
8796 . draw ( )
8897 . unwrap ( ) ;
8998
@@ -116,16 +125,21 @@ fn draw_line_comarision_figure<XR: AsRangedCoord<Value = f64>, YR: AsRangedCoord
116125
117126#[ allow( clippy:: type_complexity) ]
118127fn line_comparison_series_data < ' a > (
128+ line_cfg : LinePlotConfig ,
119129 formatter : & dyn ValueFormatter ,
120130 all_curves : & [ & ( & ' a BenchmarkId , Vec < f64 > ) ] ,
121131) -> ( & ' static str , Vec < ( Option < & ' a String > , Vec < f64 > , Vec < f64 > ) > ) {
122- let max = all_curves
132+ let ( max_id , max) = all_curves
123133 . iter ( )
124- . map ( |& ( _, data) | Sample :: new ( data) . mean ( ) )
125- . fold ( f64:: NAN , f64:: max) ;
134+ . map ( |& ( id, data) | ( * id, Sample :: new ( data) . mean ( ) ) )
135+ . fold ( None , |prev : Option < ( & BenchmarkId , f64 ) > , next| match prev {
136+ Some ( prev) if prev. 1 >= next. 1 => Some ( prev) ,
137+ _ => Some ( next) ,
138+ } )
139+ . unwrap ( ) ;
126140
127- let mut dummy = [ 1.0 ] ;
128- let unit = formatter . scale_values ( max, & mut dummy ) ;
141+ let mut max_formatted = [ max ] ;
142+ let unit = ( line_cfg . scale ) ( formatter , max_id , max, max_id , & mut max_formatted ) ;
129143
130144 let mut series_data = vec ! [ ] ;
131145
@@ -138,15 +152,16 @@ fn line_comparison_series_data<'a>(
138152 // Unwrap is fine here because it will only fail if the assumptions above are not true
139153 // ie. programmer error.
140154 let x = id. as_number ( ) . unwrap ( ) ;
141- let y = Sample :: new ( sample) . mean ( ) ;
155+ let mut y = [ Sample :: new ( sample) . mean ( ) ] ;
156+
157+ ( line_cfg. scale ) ( formatter, max_id, max, id, & mut y) ;
142158
143- ( x, y)
159+ ( x, y[ 0 ] )
144160 } )
145161 . collect ( ) ;
146162 tuples. sort_by ( |& ( ax, _) , & ( bx, _) | ( ax. partial_cmp ( & bx) . unwrap_or ( Ordering :: Less ) ) ) ;
147163 let function_name = key. as_ref ( ) ;
148- let ( xs, mut ys) : ( Vec < _ > , Vec < _ > ) = tuples. into_iter ( ) . unzip ( ) ;
149- formatter. scale_values ( max, & mut ys) ;
164+ let ( xs, ys) : ( Vec < _ > , Vec < _ > ) = tuples. into_iter ( ) . unzip ( ) ;
150165 series_data. push ( ( function_name, xs, ys) ) ;
151166 }
152167 ( unit, series_data)
0 commit comments