-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2_basic.rs
83 lines (76 loc) · 2.34 KB
/
2_basic.rs
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
use cmder::{CmderFlag, CmderOption, Command};
use criterion::{criterion_group, criterion_main, Criterion};
fn build_with_args(c: &mut Criterion) {
c.bench_function("build_with_args", |b| {
b.iter(|| {
Command::new("yargs")
.argument("<path>", "Some path")
.argument("[value]", "Some value");
})
});
}
fn build_with_flags(c: &mut Criterion) {
c.bench_function("build_with_flags", |b| {
b.iter(|| {
Command::new("flags")
.option("-x --extra", "Something extra")
.option("-v --verbose", "Verbosity");
})
});
}
fn build_w_flag_builder(c: &mut Criterion) {
c.bench_function("build_w_flag_builder", |b| {
b.iter(|| {
Command::new("flags")
.add_flag(CmderFlag::new("extra").help("Something extra").short('x'))
.add_flag(CmderFlag::new("verbose").help("Verbosity").short('v'));
})
});
}
fn build_with_options(c: &mut Criterion) {
c.bench_function("build_with_options", |b| {
b.iter(|| {
Command::new("options")
.option("-n --name [name]", "Optional name")
.required_option("-f --file-path <path>", "File path");
})
});
}
fn build_w_opt_builder(c: &mut Criterion) {
c.bench_function("build_w_opt_builder", |b| {
b.iter(|| {
Command::new("options")
.add_option(
CmderOption::new("name")
.help("optional name")
.short('n')
.argument("[name]"),
)
.add_option(
CmderOption::new("file-path")
.short('f')
.argument("<path>")
.required(true),
);
})
});
}
fn build_with_partial_args(c: &mut Criterion) {
c.bench_function("build_with_partial_args", |b| {
b.iter(|| {
Command::new("partial")
.option("--example <path>", "Path to example")
.option("-V", "Partial flag");
})
});
}
criterion_group!(
benches,
build_with_args,
build_with_flags,
build_w_flag_builder,
build_with_options,
build_w_opt_builder,
build_with_partial_args
);
criterion_main!(benches);