@@ -6,20 +6,14 @@ use std::path::{Path, PathBuf};
6
6
use std:: str:: FromStr ;
7
7
use std:: time:: Instant ;
8
8
9
+ use fast_float2:: FastFloat ;
9
10
use fastrand:: Rng ;
10
11
use lexical:: FromLexical ;
11
- use structopt:: StructOpt ;
12
-
13
- use fast_float2:: FastFloat ;
14
-
15
12
use random:: RandomGen ;
13
+ use structopt:: StructOpt ;
16
14
17
15
#[ derive( Debug , StructOpt ) ]
18
- #[ structopt(
19
- name = "fast-float-simple-bench" ,
20
- about = "fast-float benchmark utility" ,
21
- no_version
22
- ) ]
16
+ #[ structopt( name = "fast-float-simple-bench" , about = "fast-float benchmark utility" , no_version) ]
23
17
struct Opt {
24
18
/// Parse numbers as float32 (default is float64)
25
19
#[ structopt( short, long = "32" ) ]
@@ -146,9 +140,7 @@ impl Method {
146
140
fast_float:: parse_partial :: < T , _ > ( s) . unwrap_or_default ( ) . 0
147
141
} ) ,
148
142
Self :: Lexical => run_bench ( data, repeat, |s : & str | {
149
- lexical_core:: parse_partial :: < T > ( s. as_bytes ( ) )
150
- . unwrap_or_default ( )
151
- . 0
143
+ lexical_core:: parse_partial :: < T > ( s. as_bytes ( ) ) . unwrap_or_default ( ) . 0
152
144
} ) ,
153
145
Self :: FromStr => run_bench ( data, repeat, |s : & str | s. parse :: < T > ( ) . unwrap_or_default ( ) ) ,
154
146
} ;
@@ -180,12 +172,8 @@ fn print_report(results: &[BenchResult], title: &str) {
180
172
println ! ( "| {:^width$} |" , title, width = width) ;
181
173
println ! ( "|{:=<width$}|" , "" , width = width + 2 ) ;
182
174
print_table ( "ns/float" , results, width, |t, n, _| t as f64 / n as f64 ) ;
183
- print_table ( "Mfloat/s" , results, width, |t, n, _| {
184
- 1e3 * n as f64 / t as f64
185
- } ) ;
186
- print_table ( "MB/s" , results, width, |t, _, b| {
187
- b as f64 * 1e9 / 1024. / 1024. / t as f64
188
- } ) ;
175
+ print_table ( "Mfloat/s" , results, width, |t, n, _| 1e3 * n as f64 / t as f64 ) ;
176
+ print_table ( "MB/s" , results, width, |t, _, b| b as f64 * 1e9 / 1024. / 1024. / t as f64 ) ;
189
177
println ! ( "|{:width$}|" , "" , width = width + 2 ) ;
190
178
println ! ( "{:=<width$}" , "" , width = width + 4 ) ;
191
179
}
@@ -219,11 +207,7 @@ fn print_table(
219
207
for res in results {
220
208
print ! ( "| {:<h$}" , res. name, h = h) ;
221
209
let ( n, b) = ( res. count , res. bytes ) ;
222
- let mut metrics = res
223
- . times
224
- . iter ( )
225
- . map ( |& t| transform ( t, n, b) )
226
- . collect :: < Vec < _ > > ( ) ;
210
+ let mut metrics = res. times . iter ( ) . map ( |& t| transform ( t, n, b) ) . collect :: < Vec < _ > > ( ) ;
227
211
metrics. sort_by ( |a, b| a. partial_cmp ( b) . unwrap ( ) ) ;
228
212
for & ( _, idx) in columns {
229
213
print ! ( "{:>w$.2}" , metrics[ idx] , w = w) ;
@@ -240,23 +224,23 @@ struct Input {
240
224
impl Input {
241
225
pub fn from_file ( filename : impl AsRef < Path > ) -> Self {
242
226
let filename = filename. as_ref ( ) ;
243
- let data = fs:: read_to_string ( & filename)
244
- . unwrap ( )
245
- . trim ( )
246
- . lines ( )
247
- . map ( String :: from)
248
- . collect ( ) ;
227
+ let data =
228
+ fs:: read_to_string ( & filename) . unwrap ( ) . trim ( ) . lines ( ) . map ( String :: from) . collect ( ) ;
249
229
let name = filename. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . into ( ) ;
250
- Self { data, name }
230
+ Self {
231
+ data,
232
+ name,
233
+ }
251
234
}
252
235
253
236
pub fn from_random ( gen : RandomGen , count : usize , seed : u64 ) -> Self {
254
237
let mut rng = Rng :: with_seed ( seed) ;
255
- let data = iter:: repeat_with ( || gen. gen ( & mut rng) )
256
- . take ( count)
257
- . collect ( ) ;
238
+ let data = iter:: repeat_with ( || gen. gen ( & mut rng) ) . take ( count) . collect ( ) ;
258
239
let name = format ! ( "{}" , gen ) ;
259
- Self { data, name }
240
+ Self {
241
+ data,
242
+ name,
243
+ }
260
244
}
261
245
262
246
pub fn count ( & self ) -> usize {
@@ -281,14 +265,16 @@ impl Input {
281
265
fn main ( ) {
282
266
let opt: Opt = StructOpt :: from_args ( ) ;
283
267
284
- let methods = if !opt. only_fast_float && !matches ! ( & opt. command, & Cmd :: All { .. } ) {
268
+ let methods = if !opt. only_fast_float && !matches ! ( & opt. command, & Cmd :: All { .. } ) {
285
269
Method :: all ( ) . into ( )
286
270
} else {
287
271
vec ! [ Method :: FastFloat2 ]
288
272
} ;
289
273
290
274
let inputs = match opt. command {
291
- Cmd :: File { filename } => vec ! [ Input :: from_file( filename) ] ,
275
+ Cmd :: File {
276
+ filename,
277
+ } => vec ! [ Input :: from_file( filename) ] ,
292
278
Cmd :: Random {
293
279
gen,
294
280
count,
@@ -300,8 +286,11 @@ fn main() {
300
286
fs:: write ( filename, input. data . join ( "\n " ) ) . unwrap ( ) ;
301
287
}
302
288
vec ! [ input]
303
- }
304
- Cmd :: All { count, seed } => {
289
+ } ,
290
+ Cmd :: All {
291
+ count,
292
+ seed,
293
+ } => {
305
294
let mut inputs = vec ! [ ] ;
306
295
let data_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "ext/data" ) ;
307
296
inputs. push ( Input :: from_file ( data_dir. join ( "mesh.txt" ) ) ) ;
@@ -310,7 +299,7 @@ fn main() {
310
299
inputs. push ( Input :: from_random ( gen, count, seed) )
311
300
}
312
301
inputs
313
- }
302
+ } ,
314
303
} ;
315
304
316
305
let mut results = vec ! [ ] ;
0 commit comments