@@ -2,7 +2,7 @@ mod benchmark;
2
2
3
3
use crate :: benchmark:: profile:: Profile ;
4
4
use crate :: toolchain:: { get_local_toolchain, LocalToolchain } ;
5
- use benchlib:: comm:: messages:: BenchmarkMessage ;
5
+ use benchlib:: comm:: messages:: { BenchmarkMeasurement , BenchmarkMessage , BenchmarkStats } ;
6
6
use std:: io:: { BufRead , BufReader } ;
7
7
use std:: path:: { Path , PathBuf } ;
8
8
use std:: process:: { Command , Stdio } ;
@@ -50,6 +50,7 @@ pub fn bench_runtime(
50
50
benchmark_index,
51
51
filtered
52
52
) ;
53
+ print_stats ( & stats) ;
53
54
}
54
55
}
55
56
}
@@ -113,3 +114,32 @@ fn compile_runtime_benchmarks(toolchain: &LocalToolchain, dir: &Path) -> anyhow:
113
114
return Ok ( result. stdout ) ;
114
115
}
115
116
}
117
+
118
+ fn calculate_mean < I : Iterator < Item = f64 > + Clone > ( iter : I ) -> f64 {
119
+ let sum: f64 = iter. clone ( ) . sum ( ) ;
120
+ let count = iter. count ( ) ;
121
+ sum / count as f64
122
+ }
123
+
124
+ fn print_stats ( stats : & BenchmarkStats ) {
125
+ fn print_metric < F : Fn ( & BenchmarkMeasurement ) -> u64 > ( stats : & BenchmarkStats , name : & str , f : F ) {
126
+ let mean = calculate_mean ( stats. measurements . iter ( ) . map ( & f) . map ( |v| v as f64 ) ) ;
127
+ let stddev = calculate_mean (
128
+ stats
129
+ . measurements
130
+ . iter ( )
131
+ . map ( & f)
132
+ . map ( |v| ( v as f64 - mean) . powf ( 2.0 ) ) ,
133
+ )
134
+ . sqrt ( ) ;
135
+
136
+ let name = format ! ( "[{name}]" ) ;
137
+ println ! ( "{name:>20}: {:>16} (+/- {:>8})" , mean as u64 , stddev as u64 ) ;
138
+ }
139
+
140
+ print_metric ( stats, "Instructions" , |m| m. instructions ) ;
141
+ print_metric ( stats, "Cycles" , |m| m. cycles ) ;
142
+ print_metric ( stats, "Wall time [us]" , |m| m. wall_time . as_micros ( ) as u64 ) ;
143
+ print_metric ( stats, "Branch misses" , |m| m. branch_misses ) ;
144
+ print_metric ( stats, "Cache misses" , |m| m. cache_misses ) ;
145
+ }
0 commit comments