@@ -6,60 +6,71 @@ use std::path::{Path, PathBuf};
6
6
use std:: str:: FromStr ;
7
7
use std:: time:: Instant ;
8
8
9
+ use clap:: Parser ;
9
10
use fast_float2:: FastFloat ;
10
11
use fastrand:: Rng ;
11
12
use lexical:: FromLexical ;
12
13
use random:: RandomGen ;
13
- use structopt:: StructOpt ;
14
+ // use structopt::StructOpt;
14
15
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" ) ]
17
18
struct Opt {
18
19
/// Parse numbers as float32 (default is float64)
19
- #[ structopt ( short, long = "32" ) ]
20
+ #[ arg ( short, long = "32" ) ]
20
21
float32 : bool ,
22
+
21
23
/// How many times to repeat parsing
22
- #[ structopt ( short, default_value = "1000" ) ]
24
+ #[ arg ( short, long , default_value = "1000" ) ]
23
25
repeat : usize ,
26
+
24
27
/// Only run fast-float benches
25
- #[ structopt ( short) ]
28
+ #[ arg ( short, long , default_value = "false" ) ]
26
29
only_fast_float : bool ,
27
- #[ structopt( subcommand) ]
30
+
31
+ #[ command( subcommand) ]
28
32
command : Cmd ,
29
33
}
30
34
31
- #[ derive( Debug , StructOpt ) ]
35
+ #[ derive( Parser , Debug ) ]
36
+ #[ command( version, about, long_about = None ) ]
32
37
enum Cmd {
33
38
/// Read the floats from file
34
39
File {
35
40
/// Input file (one number per line)
36
- #[ structopt ( parse ( from_os_str ) ) ]
41
+ #[ arg ( value_parser ) ]
37
42
filename : PathBuf ,
38
43
} ,
44
+
39
45
/// Generate random floats in (0, 1]
40
46
Random {
41
47
/// Random generator to be used
42
- #[ structopt(
48
+ #[ arg(
49
+ value_enum,
43
50
default_value = "uniform" ,
44
- parse( try_from_str) ,
45
- possible_values = RandomGen :: variants( )
51
+ //possible_values = RandomGen::variants()
46
52
) ]
47
53
gen : RandomGen ,
54
+
48
55
/// Number of random floats generated
49
- #[ structopt ( short = "n" , default_value = "50000" ) ]
56
+ #[ arg ( short = 'n' , default_value = "50000" ) ]
50
57
count : usize ,
58
+
51
59
/// Random generator seed
52
- #[ structopt ( short, default_value = "0" ) ]
60
+ #[ arg ( short, default_value = "0" ) ]
53
61
seed : u64 ,
62
+
54
63
/// Also save the generated inputs to file
55
- #[ structopt ( short = "f" , parse ( from_os_str ) ) ]
64
+ #[ arg ( value_parser , short = 'f' ) ]
56
65
filename : Option < PathBuf > ,
57
66
} ,
67
+
58
68
/// Run all benchmarks for fast-float only
59
69
All {
60
70
/// Number of random floats generated
61
- #[ structopt( short = "n" , default_value = "50000" ) ]
71
+ #[ structopt( short = 'n' , default_value = "50000" ) ]
62
72
count : usize ,
73
+
63
74
/// Random generator seed
64
75
#[ structopt( short, default_value = "0" ) ]
65
76
seed : u64 ,
@@ -263,7 +274,7 @@ impl Input {
263
274
}
264
275
265
276
fn main ( ) {
266
- let opt: Opt = StructOpt :: from_args ( ) ;
277
+ let opt = Opt :: parse ( ) ;
267
278
268
279
let methods = if !opt. only_fast_float && !matches ! ( & opt. command, & Cmd :: All { .. } ) {
269
280
Method :: all ( ) . into ( )
0 commit comments