@@ -6,20 +6,14 @@ use std::path::{Path, PathBuf};
66use std:: str:: FromStr ;
77use std:: time:: Instant ;
88
9+ use fast_float2:: FastFloat ;
910use fastrand:: Rng ;
1011use lexical:: FromLexical ;
11- use structopt:: StructOpt ;
12-
13- use fast_float2:: FastFloat ;
14-
1512use random:: RandomGen ;
13+ use structopt:: StructOpt ;
1614
1715#[ 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) ]
2317struct Opt {
2418 /// Parse numbers as float32 (default is float64)
2519 #[ structopt( short, long = "32" ) ]
@@ -146,9 +140,7 @@ impl Method {
146140 fast_float:: parse_partial :: < T , _ > ( s) . unwrap_or_default ( ) . 0
147141 } ) ,
148142 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
152144 } ) ,
153145 Self :: FromStr => run_bench ( data, repeat, |s : & str | s. parse :: < T > ( ) . unwrap_or_default ( ) ) ,
154146 } ;
@@ -180,12 +172,8 @@ fn print_report(results: &[BenchResult], title: &str) {
180172 println ! ( "| {:^width$} |" , title, width = width) ;
181173 println ! ( "|{:=<width$}|" , "" , width = width + 2 ) ;
182174 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 ) ;
189177 println ! ( "|{:width$}|" , "" , width = width + 2 ) ;
190178 println ! ( "{:=<width$}" , "" , width = width + 4 ) ;
191179}
@@ -219,11 +207,7 @@ fn print_table(
219207 for res in results {
220208 print ! ( "| {:<h$}" , res. name, h = h) ;
221209 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 < _ > > ( ) ;
227211 metrics. sort_by ( |a, b| a. partial_cmp ( b) . unwrap ( ) ) ;
228212 for & ( _, idx) in columns {
229213 print ! ( "{:>w$.2}" , metrics[ idx] , w = w) ;
@@ -240,23 +224,23 @@ struct Input {
240224impl Input {
241225 pub fn from_file ( filename : impl AsRef < Path > ) -> Self {
242226 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 ( ) ;
249229 let name = filename. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . into ( ) ;
250- Self { data, name }
230+ Self {
231+ data,
232+ name,
233+ }
251234 }
252235
253236 pub fn from_random ( gen : RandomGen , count : usize , seed : u64 ) -> Self {
254237 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 ( ) ;
258239 let name = format ! ( "{}" , gen ) ;
259- Self { data, name }
240+ Self {
241+ data,
242+ name,
243+ }
260244 }
261245
262246 pub fn count ( & self ) -> usize {
@@ -281,14 +265,16 @@ impl Input {
281265fn main ( ) {
282266 let opt: Opt = StructOpt :: from_args ( ) ;
283267
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 { .. } ) {
285269 Method :: all ( ) . into ( )
286270 } else {
287271 vec ! [ Method :: FastFloat2 ]
288272 } ;
289273
290274 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) ] ,
292278 Cmd :: Random {
293279 gen,
294280 count,
@@ -300,8 +286,11 @@ fn main() {
300286 fs:: write ( filename, input. data . join ( "\n " ) ) . unwrap ( ) ;
301287 }
302288 vec ! [ input]
303- }
304- Cmd :: All { count, seed } => {
289+ } ,
290+ Cmd :: All {
291+ count,
292+ seed,
293+ } => {
305294 let mut inputs = vec ! [ ] ;
306295 let data_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "ext/data" ) ;
307296 inputs. push ( Input :: from_file ( data_dir. join ( "mesh.txt" ) ) ) ;
@@ -310,7 +299,7 @@ fn main() {
310299 inputs. push ( Input :: from_random ( gen, count, seed) )
311300 }
312301 inputs
313- }
302+ } ,
314303 } ;
315304
316305 let mut results = vec ! [ ] ;
0 commit comments