diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/clap/benches/02_simple.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/clap/benches/02_simple.rs')
-rw-r--r-- | third_party/rust/clap/benches/02_simple.rs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/third_party/rust/clap/benches/02_simple.rs b/third_party/rust/clap/benches/02_simple.rs new file mode 100644 index 0000000000..667d02f873 --- /dev/null +++ b/third_party/rust/clap/benches/02_simple.rs @@ -0,0 +1,104 @@ +use clap::{arg, Arg, Command}; +use criterion::{criterion_group, criterion_main, Criterion}; + +macro_rules! create_app { + () => {{ + Command::new("claptests") + .version("0.1") + .about("tests clap library") + .author("Kevin K. <kbknapp@gmail.com>") + .arg(arg!(-f --flag "tests flags")) + .arg(arg!(-o --option <opt> "tests options").required(false)) + .arg(arg!([positional] "tests positional")) + }}; +} + +pub fn build_simple(c: &mut Criterion) { + c.bench_function("build_simple", |b| b.iter(|| create_app!())); +} + +pub fn build_with_flag(c: &mut Criterion) { + c.bench_function("build_with_flag", |b| { + b.iter(|| Command::new("claptests").arg(arg!(-s --some "something"))) + }); +} + +pub fn build_with_flag_ref(c: &mut Criterion) { + c.bench_function("build_with_flag_ref", |b| { + b.iter(|| { + let arg = arg!(-s --some "something"); + Command::new("claptests").arg(&arg) + }) + }); +} + +pub fn build_with_opt(c: &mut Criterion) { + c.bench_function("build_with_opt", |b| { + b.iter(|| Command::new("claptests").arg(arg!(-s --some <FILE> "something"))) + }); +} + +pub fn build_with_opt_ref(c: &mut Criterion) { + c.bench_function("build_with_opt_ref", |b| { + b.iter(|| { + let arg = arg!(-s --some <FILE> "something"); + Command::new("claptests").arg(&arg) + }) + }); +} + +pub fn build_with_pos(c: &mut Criterion) { + c.bench_function("build_with_pos", |b| { + b.iter(|| Command::new("claptests").arg(Arg::new("some"))) + }); +} + +pub fn build_with_pos_ref(c: &mut Criterion) { + c.bench_function("build_with_pos_ref", |b| { + b.iter(|| { + let arg = Arg::new("some"); + Command::new("claptests").arg(&arg) + }) + }); +} + +pub fn parse_simple_with_flag(c: &mut Criterion) { + c.bench_function("parse_simple_with_flag", |b| { + b.iter(|| create_app!().get_matches_from(vec!["myprog", "-f"])) + }); +} + +pub fn parse_simple_with_opt(c: &mut Criterion) { + c.bench_function("parse_simple_with_opt", |b| { + b.iter(|| create_app!().get_matches_from(vec!["myprog", "-o", "option1"])) + }); +} + +pub fn parse_simple_with_pos(c: &mut Criterion) { + c.bench_function("parse_simple_with_pos", |b| { + b.iter(|| create_app!().get_matches_from(vec!["myprog", "arg1"])) + }); +} + +pub fn parse_simple_with_complex(c: &mut Criterion) { + c.bench_function("parse_simple_with_complex", |b| { + b.iter(|| create_app!().get_matches_from(vec!["myprog", "-o", "option1", "-f", "arg1"])) + }); +} + +criterion_group!( + benches, + 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 +); + +criterion_main!(benches); |