@@ -19,7 +19,7 @@ pub struct Benchmark {
19
19
name : String ,
20
20
nanoseconds : f64 ,
21
21
stddev : Option < f64 > ,
22
- bytes_per_second : Option < f64 > ,
22
+ throughput : Option < data :: Throughput > ,
23
23
/// Whether this is the best benchmark in a group. This is only populated
24
24
/// when a `Comparison` is built.
25
25
best : bool ,
@@ -74,7 +74,7 @@ impl Benchmark {
74
74
name : b. fullname ( ) . to_string ( ) ,
75
75
nanoseconds : b. nanoseconds ( ) ,
76
76
stddev : Some ( b. stddev ( ) ) ,
77
- bytes_per_second : b. bytes_per_second ( ) ,
77
+ throughput : b. throughput ( ) ,
78
78
best : false ,
79
79
rank : 0.0 ,
80
80
}
@@ -134,7 +134,7 @@ pub fn columns<W: WriteColor>(
134
134
"\t {:<5.2} {:>14} {:>14}" ,
135
135
b. rank,
136
136
time( b. nanoseconds, b. stddev) ,
137
- throughput( b. bytes_per_second ) ,
137
+ throughput( b. throughput ) ,
138
138
) ?;
139
139
if b. best {
140
140
wtr. reset ( ) ?;
@@ -172,7 +172,7 @@ fn rows_one<W: WriteColor>(mut wtr: W, group: &Comparison) -> Result<()> {
172
172
b. name,
173
173
b. rank,
174
174
time( b. nanoseconds, b. stddev) ,
175
- throughput( b. bytes_per_second ) ,
175
+ throughput( b. throughput ) ,
176
176
) ?;
177
177
}
178
178
Ok ( ( ) )
@@ -209,22 +209,27 @@ fn time(nanos: f64, stddev: Option<f64>) -> String {
209
209
}
210
210
}
211
211
212
- fn throughput ( bytes_per_second : Option < f64 > ) -> String {
213
- const MIN_KB : f64 = ( 2 * ( 1 << 10 ) as u64 ) as f64 ;
214
- const MIN_MB : f64 = ( 2 * ( 1 << 20 ) as u64 ) as f64 ;
215
- const MIN_GB : f64 = ( 2 * ( 1 << 30 ) as u64 ) as f64 ;
212
+ fn throughput ( throughput : Option < data:: Throughput > ) -> String {
213
+ use data:: Throughput :: * ;
214
+ match throughput {
215
+ Some ( Bytes ( num) ) => throughput_per ( num, "B" ) ,
216
+ Some ( Elements ( num) ) => throughput_per ( num, "Elem" ) ,
217
+ _ => "? ?/sec" . to_string ( ) ,
218
+ }
219
+ }
216
220
217
- let per = match bytes_per_second {
218
- None => return "? B/sec" . to_string ( ) ,
219
- Some ( per) => per,
220
- } ;
221
- if per < MIN_KB {
222
- format ! ( "{} B/sec" , per as u64 )
223
- } else if per < MIN_MB {
224
- format ! ( "{:.1} KB/sec" , ( per / ( 1 << 10 ) as f64 ) )
225
- } else if per < MIN_GB {
226
- format ! ( "{:.1} MB/sec" , ( per / ( 1 << 20 ) as f64 ) )
221
+ fn throughput_per ( per : f64 , unit : & str ) -> String {
222
+ const MIN_K : f64 = ( 2 * ( 1 << 10 ) as u64 ) as f64 ;
223
+ const MIN_M : f64 = ( 2 * ( 1 << 20 ) as u64 ) as f64 ;
224
+ const MIN_G : f64 = ( 2 * ( 1 << 30 ) as u64 ) as f64 ;
225
+
226
+ if per < MIN_K {
227
+ format ! ( "{} {}/sec" , per as u64 , unit)
228
+ } else if per < MIN_M {
229
+ format ! ( "{:.1} K{}/sec" , ( per / ( 1 << 10 ) as f64 ) , unit)
230
+ } else if per < MIN_G {
231
+ format ! ( "{:.1} M{}/sec" , ( per / ( 1 << 20 ) as f64 ) , unit)
227
232
} else {
228
- format ! ( "{:.1} GB /sec" , ( per / ( 1 << 30 ) as f64 ) )
233
+ format ! ( "{:.1} G{} /sec" , ( per / ( 1 << 30 ) as f64 ) , unit )
229
234
}
230
235
}
0 commit comments