clap/benches/02_simple.rs

105 lines
2.9 KiB
Rust
Raw Normal View History

use clap::{App, Arg};
2020-02-17 21:14:19 +03:00
use criterion::{criterion_group, criterion_main, Criterion};
2015-09-01 11:00:51 -05:00
macro_rules! create_app {
2018-08-01 23:13:51 -04:00
() => {{
2015-09-01 11:00:51 -05:00
App::new("claptests")
2018-08-01 23:13:51 -04:00
.version("0.1")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
2018-11-13 22:16:02 -05:00
.arg("-f --flag 'tests flags'")
.arg("-o --option=[opt] 'tests options'")
.arg("[positional] 'tests positional'")
2018-08-01 23:13:51 -04:00
}};
2015-09-01 11:00:51 -05:00
}
2020-03-05 10:06:17 +01:00
pub fn build_simple(c: &mut Criterion) {
c.bench_function("build_simple", |b| b.iter(|| create_app!()));
2020-01-31 10:13:44 +01:00
}
2015-09-01 11:00:51 -05:00
2020-03-05 10:06:17 +01:00
pub fn build_with_flag(c: &mut Criterion) {
c.bench_function("build_with_flag", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| App::new("claptests").arg(Arg::from("-s, --some 'something'")))
});
}
2020-03-05 10:06:17 +01:00
pub fn build_with_flag_ref(c: &mut Criterion) {
c.bench_function("build_with_flag_ref", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| {
let arg = Arg::from("-s, --some 'something'");
App::new("claptests").arg(&arg)
})
});
}
2020-03-05 10:06:17 +01:00
pub fn build_with_opt(c: &mut Criterion) {
c.bench_function("build_with_opt", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| App::new("claptests").arg(Arg::from("-s, --some <FILE> 'something'")))
});
}
2020-03-05 10:06:17 +01:00
pub fn build_with_opt_ref(c: &mut Criterion) {
c.bench_function("build_with_opt_ref", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| {
let arg = Arg::from("-s, --some <FILE> 'something'");
App::new("claptests").arg(&arg)
})
});
}
2020-03-05 10:06:17 +01:00
pub fn build_with_pos(c: &mut Criterion) {
c.bench_function("build_with_pos", |b| {
b.iter(|| App::new("claptests").arg(Arg::new("some")))
2020-02-21 03:12:28 +03:00
});
}
2020-03-05 10:06:17 +01:00
pub fn build_with_pos_ref(c: &mut Criterion) {
c.bench_function("build_with_pos_ref", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| {
let arg = Arg::new("some");
2020-02-21 03:12:28 +03:00
App::new("claptests").arg(&arg)
})
});
}
2020-03-05 10:06:17 +01:00
pub fn parse_simple_with_flag(c: &mut Criterion) {
c.bench_function("parse_simple_with_flag", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-f"]))
});
2020-01-31 10:13:44 +01:00
}
2015-09-01 11:00:51 -05:00
2020-03-05 10:06:17 +01:00
pub fn parse_simple_with_opt(c: &mut Criterion) {
c.bench_function("parse_simple_with_opt", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-o", "option1"]))
});
2020-01-31 10:13:44 +01:00
}
2015-09-01 11:00:51 -05:00
2020-03-05 10:06:17 +01:00
pub fn parse_simple_with_pos(c: &mut Criterion) {
c.bench_function("parse_simple_with_pos", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| create_app!().get_matches_from(vec!["myprog", "arg1"]))
});
2015-09-01 11:00:51 -05:00
}
2020-03-05 10:06:17 +01:00
pub fn parse_simple_with_complex(c: &mut Criterion) {
c.bench_function("parse_simple_with_complex", |b| {
2020-02-21 03:12:28 +03:00
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-o", "option1", "-f", "arg1"]))
});
2015-09-01 11:00:51 -05:00
}
2020-02-21 03:12:28 +03:00
criterion_group!(
benches,
2020-03-05 10:06:17 +01:00
parse_simple_with_complex,
parse_simple_with_pos,
parse_simple_with_opt,
parse_simple_with_flag,
build_with_pos_ref,
build_with_pos,
build_with_opt_ref,
build_with_opt,
build_with_flag_ref,
build_with_flag,
build_simple
2020-02-17 21:14:19 +03:00
);
criterion_main!(benches);