2015-09-01 16:00:51 +00:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate clap;
|
|
|
|
extern crate test;
|
|
|
|
|
2017-03-04 19:53:15 +00:00
|
|
|
use clap::{App, Arg};
|
2015-09-01 16:00:51 +00:00
|
|
|
|
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
macro_rules! create_app {
|
2018-08-02 03:13:51 +00:00
|
|
|
() => {{
|
2015-09-01 16:00:51 +00:00
|
|
|
App::new("claptests")
|
2018-08-02 03:13:51 +00:00
|
|
|
.version("0.1")
|
|
|
|
.about("tests clap library")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
2018-11-14 03:16:02 +00:00
|
|
|
.arg("-f --flag 'tests flags'")
|
|
|
|
.arg("-o --option=[opt] 'tests options'")
|
|
|
|
.arg("[positional] 'tests positional'")
|
2018-08-02 03:13:51 +00:00
|
|
|
}};
|
2015-09-01 16:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2018-01-25 04:05:05 +00:00
|
|
|
fn build_app(b: &mut Bencher) { b.iter(|| create_app!()); }
|
2015-09-01 16:00:51 +00:00
|
|
|
|
2017-03-04 19:53:15 +00:00
|
|
|
#[bench]
|
|
|
|
fn add_flag(b: &mut Bencher) {
|
2019-04-05 19:34:35 +00:00
|
|
|
fn build_app() -> App<'static> { App::new("claptests") }
|
2017-03-04 19:53:15 +00:00
|
|
|
|
2018-04-21 18:59:19 +00:00
|
|
|
b.iter(|| build_app().arg(Arg::from("-s, --some 'something'")));
|
2017-03-04 19:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn add_flag_ref(b: &mut Bencher) {
|
2019-04-05 19:34:35 +00:00
|
|
|
fn build_app() -> App<'static> { App::new("claptests") }
|
2017-03-04 19:53:15 +00:00
|
|
|
|
|
|
|
b.iter(|| {
|
2018-04-21 18:59:19 +00:00
|
|
|
let arg = Arg::from("-s, --some 'something'");
|
2017-03-04 19:53:15 +00:00
|
|
|
build_app().arg(&arg)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn add_opt(b: &mut Bencher) {
|
2019-04-05 19:34:35 +00:00
|
|
|
fn build_app() -> App<'static> { App::new("claptests") }
|
2017-03-04 19:53:15 +00:00
|
|
|
|
2018-04-21 18:59:19 +00:00
|
|
|
b.iter(|| build_app().arg(Arg::from("-s, --some <FILE> 'something'")));
|
2017-03-04 19:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn add_opt_ref(b: &mut Bencher) {
|
2019-04-05 19:34:35 +00:00
|
|
|
fn build_app() -> App<'static> { App::new("claptests") }
|
2017-03-04 19:53:15 +00:00
|
|
|
|
|
|
|
b.iter(|| {
|
2018-04-21 18:59:19 +00:00
|
|
|
let arg = Arg::from("-s, --some <FILE> 'something'");
|
2017-03-04 19:53:15 +00:00
|
|
|
build_app().arg(&arg)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn add_pos(b: &mut Bencher) {
|
2019-04-05 19:34:35 +00:00
|
|
|
fn build_app() -> App<'static> { App::new("claptests") }
|
2017-03-04 19:53:15 +00:00
|
|
|
|
|
|
|
b.iter(|| build_app().arg(Arg::with_name("some")));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn add_pos_ref(b: &mut Bencher) {
|
2019-04-05 19:34:35 +00:00
|
|
|
fn build_app() -> App<'static> { App::new("claptests") }
|
2017-03-04 19:53:15 +00:00
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
let arg = Arg::with_name("some");
|
|
|
|
build_app().arg(&arg)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-09-01 16:00:51 +00:00
|
|
|
#[bench]
|
2018-01-25 04:05:05 +00:00
|
|
|
fn parse_clean(b: &mut Bencher) { b.iter(|| create_app!().get_matches_from(vec![""])); }
|
2015-09-01 16:00:51 +00:00
|
|
|
|
|
|
|
#[bench]
|
2018-01-25 04:05:05 +00:00
|
|
|
fn parse_flag(b: &mut Bencher) { b.iter(|| create_app!().get_matches_from(vec!["myprog", "-f"])); }
|
2015-09-01 16:00:51 +00:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn parse_option(b: &mut Bencher) {
|
2016-01-21 05:18:53 +00:00
|
|
|
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-o", "option1"]));
|
2015-09-01 16:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn parse_positional(b: &mut Bencher) {
|
2016-01-21 05:18:53 +00:00
|
|
|
b.iter(|| create_app!().get_matches_from(vec!["myprog", "arg1"]));
|
2015-09-01 16:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn parse_complex(b: &mut Bencher) {
|
2016-01-21 05:18:53 +00:00
|
|
|
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-o", "option1", "-f", "arg1"]));
|
2015-09-01 16:00:51 +00:00
|
|
|
}
|