1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#![feature(test)]
extern crate clap;
extern crate test;
use clap::{App, Arg};
use test::Bencher;
macro_rules! create_app {
() => ({
App::new("claptests")
.version("0.1")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
.args_from_usage("-f --flag 'tests flags'
-o --option=[opt] 'tests options'
[positional] 'tests positional'")
})
}
#[bench]
fn build_app(b: &mut Bencher) {
b.iter(|| create_app!());
}
#[bench]
fn add_flag(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> {
App::new("claptests")
}
b.iter(|| build_app().arg(Arg::from_usage("-s, --some 'something'")));
}
#[bench]
fn add_flag_ref(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> {
App::new("claptests")
}
b.iter(|| {
let arg = Arg::from_usage("-s, --some 'something'");
build_app().arg(&arg)
});
}
#[bench]
fn add_opt(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> {
App::new("claptests")
}
b.iter(|| build_app().arg(Arg::from_usage("-s, --some <FILE> 'something'")));
}
#[bench]
fn add_opt_ref(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> {
App::new("claptests")
}
b.iter(|| {
let arg = Arg::from_usage("-s, --some <FILE> 'something'");
build_app().arg(&arg)
});
}
#[bench]
fn add_pos(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> {
App::new("claptests")
}
b.iter(|| build_app().arg(Arg::with_name("some")));
}
#[bench]
fn add_pos_ref(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> {
App::new("claptests")
}
b.iter(|| {
let arg = Arg::with_name("some");
build_app().arg(&arg)
});
}
#[bench]
fn parse_clean(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec![""]));
}
#[bench]
fn parse_flag(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-f"]));
}
#[bench]
fn parse_option(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-o", "option1"]));
}
#[bench]
fn parse_positional(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec!["myprog", "arg1"]));
}
#[bench]
fn parse_complex(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-o", "option1", "-f", "arg1"]));
}
|