@@ -6,60 +6,71 @@ use std::path::{Path, PathBuf};
66use std:: str:: FromStr ;
77use std:: time:: Instant ;
88
9+ use clap:: Parser ;
910use fast_float2:: FastFloat ;
1011use fastrand:: Rng ;
1112use lexical:: FromLexical ;
1213use random:: RandomGen ;
13- use structopt:: StructOpt ;
14+ // use structopt::StructOpt;
1415
15- #[ derive( Debug , StructOpt ) ]
16- #[ structopt ( name = "fast-float-simple-bench" , about = "fast-float benchmark utility" , no_version ) ]
16+ #[ derive( Parser , Debug ) ]
17+ #[ command ( name = "fast-float-simple-bench" , about = "fast-float benchmark utility" ) ]
1718struct Opt {
1819 /// Parse numbers as float32 (default is float64)
19- #[ structopt ( short, long = "32" ) ]
20+ #[ arg ( short, long = "32" ) ]
2021 float32 : bool ,
22+
2123 /// How many times to repeat parsing
22- #[ structopt ( short, default_value = "1000" ) ]
24+ #[ arg ( short, long , default_value = "1000" ) ]
2325 repeat : usize ,
26+
2427 /// Only run fast-float benches
25- #[ structopt ( short) ]
28+ #[ arg ( short, long , default_value = "false" ) ]
2629 only_fast_float : bool ,
27- #[ structopt( subcommand) ]
30+
31+ #[ command( subcommand) ]
2832 command : Cmd ,
2933}
3034
31- #[ derive( Debug , StructOpt ) ]
35+ #[ derive( Parser , Debug ) ]
36+ #[ command( version, about, long_about = None ) ]
3237enum Cmd {
3338 /// Read the floats from file
3439 File {
3540 /// Input file (one number per line)
36- #[ structopt ( parse ( from_os_str ) ) ]
41+ #[ arg ( value_parser ) ]
3742 filename : PathBuf ,
3843 } ,
44+
3945 /// Generate random floats in (0, 1]
4046 Random {
4147 /// Random generator to be used
42- #[ structopt(
48+ #[ arg(
49+ value_enum,
4350 default_value = "uniform" ,
44- parse( try_from_str) ,
45- possible_values = RandomGen :: variants( )
51+ //possible_values = RandomGen::variants()
4652 ) ]
4753 gen : RandomGen ,
54+
4855 /// Number of random floats generated
49- #[ structopt ( short = "n" , default_value = "50000" ) ]
56+ #[ arg ( short = 'n' , default_value = "50000" ) ]
5057 count : usize ,
58+
5159 /// Random generator seed
52- #[ structopt ( short, default_value = "0" ) ]
60+ #[ arg ( short, default_value = "0" ) ]
5361 seed : u64 ,
62+
5463 /// Also save the generated inputs to file
55- #[ structopt ( short = "f" , parse ( from_os_str ) ) ]
64+ #[ arg ( value_parser , short = 'f' ) ]
5665 filename : Option < PathBuf > ,
5766 } ,
67+
5868 /// Run all benchmarks for fast-float only
5969 All {
6070 /// Number of random floats generated
61- #[ structopt( short = "n" , default_value = "50000" ) ]
71+ #[ structopt( short = 'n' , default_value = "50000" ) ]
6272 count : usize ,
73+
6374 /// Random generator seed
6475 #[ structopt( short, default_value = "0" ) ]
6576 seed : u64 ,
@@ -263,7 +274,7 @@ impl Input {
263274}
264275
265276fn main ( ) {
266- let opt: Opt = StructOpt :: from_args ( ) ;
277+ let opt = Opt :: parse ( ) ;
267278
268279 let methods = if !opt. only_fast_float && !matches ! ( & opt. command, & Cmd :: All { .. } ) {
269280 Method :: all ( ) . into ( )
0 commit comments