Skip to content

Commit

Permalink
style: rustfmt run
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Jan 25, 2018
1 parent f66e4f3 commit 1ab1027
Show file tree
Hide file tree
Showing 73 changed files with 3,679 additions and 3,070 deletions.
8 changes: 2 additions & 6 deletions benches/01_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ use clap::App;
use test::Bencher;

#[bench]
fn build_app(b: &mut Bencher) {
b.iter(|| App::new("claptests"));
}
fn build_app(b: &mut Bencher) { b.iter(|| App::new("claptests")); }

#[bench]
fn parse_clean(b: &mut Bencher) {
b.iter(|| App::new("claptests").get_matches_from(vec![""]));
}
fn parse_clean(b: &mut Bencher) { b.iter(|| App::new("claptests").get_matches_from(vec![""])); }
37 changes: 9 additions & 28 deletions benches/02_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,18 @@ macro_rules! create_app {
}

#[bench]
fn build_app(b: &mut Bencher) {

b.iter(|| create_app!());
}
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")
}
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")
}
fn build_app() -> App<'static, 'static> { App::new("claptests") }

b.iter(|| {
let arg = Arg::from_usage("-s, --some 'something'");
Expand All @@ -48,18 +41,14 @@ fn add_flag_ref(b: &mut Bencher) {

#[bench]
fn add_opt(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> {
App::new("claptests")
}
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")
}
fn build_app() -> App<'static, 'static> { App::new("claptests") }

b.iter(|| {
let arg = Arg::from_usage("-s, --some <FILE> 'something'");
Expand All @@ -69,18 +58,14 @@ fn add_opt_ref(b: &mut Bencher) {

#[bench]
fn add_pos(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> {
App::new("claptests")
}
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")
}
fn build_app() -> App<'static, 'static> { App::new("claptests") }

b.iter(|| {
let arg = Arg::with_name("some");
Expand All @@ -89,14 +74,10 @@ fn add_pos_ref(b: &mut Bencher) {
}

#[bench]
fn parse_clean(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec![""]));
}
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"]));
}
fn parse_flag(b: &mut Bencher) { b.iter(|| create_app!().get_matches_from(vec!["myprog", "-f"])); }

#[bench]
fn parse_option(b: &mut Bencher) {
Expand Down
190 changes: 134 additions & 56 deletions benches/03_complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern crate clap;
extern crate test;

use clap::{App, Arg, SubCommand, AppSettings};
use clap::{App, AppSettings, Arg, SubCommand};

use test::Bencher;

Expand Down Expand Up @@ -43,94 +43,121 @@ macro_rules! create_app {
}

#[bench]
fn create_app_from_usage(b: &mut Bencher) {

b.iter(|| create_app!());
}
fn create_app_from_usage(b: &mut Bencher) { b.iter(|| create_app!()); }

#[bench]
fn create_app_builder(b: &mut Bencher) {
b.iter(|| {
App::new("claptests")
.version("0.1")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
.arg(Arg::with_name("opt")
.version("0.1")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
.arg(
Arg::with_name("opt")
.help("tests options")
.short("o")
.long("option")
.takes_value(true)
.multiple(true))
.arg(Arg::with_name("positional")
.multiple(true),
)
.arg(
Arg::with_name("positional")
.help("tests positionals")
.index(1))
.arg(Arg::with_name("flag")
.short("f")
.help("tests flags")
.long("flag")
.multiple(true)
.global(true))
.arg(Arg::with_name("flag2")
.index(1),
)
.arg(
Arg::with_name("flag")
.short("f")
.help("tests flags")
.long("flag")
.multiple(true)
.global(true),
)
.arg(
Arg::with_name("flag2")
.short("F")
.help("tests flags with exclusions")
.conflicts_with("flag")
.requires("option2"))
.arg(Arg::with_name("option2")
.requires("option2"),
)
.arg(
Arg::with_name("option2")
.help("tests long options with exclusions")
.conflicts_with("option")
.requires("positional2")
.takes_value(true)
.long("long-option-2"))
.arg(Arg::with_name("positional2")
.long("long-option-2"),
)
.arg(
Arg::with_name("positional2")
.index(3)
.help("tests positionals with exclusions"))
.arg(Arg::with_name("option3")
.help("tests positionals with exclusions"),
)
.arg(
Arg::with_name("option3")
.short("O")
.long("Option")
.takes_value(true)
.help("tests options with specific value sets")
.possible_values(&OPT3_VALS))
.arg(Arg::with_name("positional3")
.possible_values(&OPT3_VALS),
)
.arg(
Arg::with_name("positional3")
.multiple(true)
.help("tests positionals with specific values")
.index(4)
.possible_values(&POS3_VALS))
.arg(Arg::with_name("multvals")
.possible_values(&POS3_VALS),
)
.arg(
Arg::with_name("multvals")
.long("multvals")
.takes_value(true)
.help("Tests mutliple values, not mult occs")
.value_names(&["one", "two"]))
.arg(Arg::with_name("multvalsmo")
.value_names(&["one", "two"]),
)
.arg(
Arg::with_name("multvalsmo")
.long("multvalsmo")
.takes_value(true)
.multiple(true)
.help("Tests mutliple values, not mult occs")
.value_names(&["one", "two"]))
.arg(Arg::with_name("minvals")
.value_names(&["one", "two"]),
)
.arg(
Arg::with_name("minvals")
.long("minvals2")
.multiple(true)
.takes_value(true)
.help("Tests 2 min vals")
.min_values(2))
.arg(Arg::with_name("maxvals")
.min_values(2),
)
.arg(
Arg::with_name("maxvals")
.long("maxvals3")
.takes_value(true)
.multiple(true)
.help("Tests 3 max vals")
.max_values(3))
.subcommand(SubCommand::with_name("subcmd")
.max_values(3),
)
.subcommand(
SubCommand::with_name("subcmd")
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <kbknapp@gmail.com>")
.arg(Arg::with_name("scoption")
.short("o")
.long("option")
.multiple(true)
.takes_value(true)
.help("tests options"))
.arg(Arg::with_name("scpositional")
.index(1)
.help("tests positionals")));
.arg(
Arg::with_name("scoption")
.short("o")
.long("option")
.multiple(true)
.takes_value(true)
.help("tests options"),
)
.arg(
Arg::with_name("scpositional")
.index(1)
.help("tests positionals"),
),
);
});
}

Expand Down Expand Up @@ -170,14 +197,10 @@ fn create_app_macros(b: &mut Bencher) {
}

#[bench]
fn parse_clean(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec![""]));
}
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"]));
}
fn parse_flag(b: &mut Bencher) { b.iter(|| create_app!().get_matches_from(vec!["myprog", "-f"])); }

#[bench]
fn parse_option(b: &mut Bencher) {
Expand Down Expand Up @@ -211,20 +234,75 @@ fn parse_sc_positional(b: &mut Bencher) {

#[bench]
fn parse_complex1(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec!["myprog", "-ff", "-o", "option1", "arg1", "-O", "fast", "arg2", "--multvals", "one", "two", "emacs"]));
b.iter(|| {
create_app!().get_matches_from(vec![
"myprog",
"-ff",
"-o",
"option1",
"arg1",
"-O",
"fast",
"arg2",
"--multvals",
"one",
"two",
"emacs",
])
});
}

#[bench]
fn parse_complex2(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec!["myprog", "arg1", "-f", "arg2", "--long-option-2", "some", "-O", "slow", "--multvalsmo", "one", "two", "--minvals2", "3", "2", "1"]));
b.iter(|| {
create_app!().get_matches_from(vec![
"myprog",
"arg1",
"-f",
"arg2",
"--long-option-2",
"some",
"-O",
"slow",
"--multvalsmo",
"one",
"two",
"--minvals2",
"3",
"2",
"1",
])
});
}

#[bench]
fn parse_complex2_with_args_negate_scs(b: &mut Bencher) {
b.iter(|| create_app!().setting(AppSettings::ArgsNegateSubcommands).get_matches_from(vec!["myprog", "arg1", "-f", "arg2", "--long-option-2", "some", "-O", "slow", "--multvalsmo", "one", "two", "--minvals2", "3", "2", "1"]));
b.iter(|| {
create_app!()
.setting(AppSettings::ArgsNegateSubcommands)
.get_matches_from(vec![
"myprog",
"arg1",
"-f",
"arg2",
"--long-option-2",
"some",
"-O",
"slow",
"--multvalsmo",
"one",
"two",
"--minvals2",
"3",
"2",
"1",
])
});
}

#[bench]
fn parse_sc_complex(b: &mut Bencher) {
b.iter(|| create_app!().get_matches_from(vec!["myprog", "subcmd", "-f", "-o", "option1", "arg1"]));
b.iter(|| {
create_app!().get_matches_from(vec!["myprog", "subcmd", "-f", "-o", "option1", "arg1"])
});
}
Loading

0 comments on commit 1ab1027

Please sign in to comment.