Use criterion.rs for section benchmarking (#8)

### Changes
- Replace Rust nightly built-in benchmarking with criterion.rs
- Add benchmarking to Azure Pipelines
This commit is contained in:
Matan Kushner
2019-04-16 12:20:00 -07:00
committed by GitHub
parent fd42d81273
commit 2017bcfc7a
5 changed files with 336 additions and 69 deletions
-69
View File
@@ -1,69 +0,0 @@
#![feature(test)]
extern crate test;
#[cfg(test)]
mod tests {
use clap::{App, Arg};
use starship::modules;
use test::Bencher;
// #[bench]
// fn full_prompt_bench(b: &mut Bencher) {
// b.iter(|| {
// let args = App::new("starship")
// .arg(Arg::with_name("status_code"))
// .get_matches_from(vec!["starship", "0"]);
// starship::print::prompt(args)
// });
// }
#[bench]
fn char_section_bench(b: &mut Bencher) {
b.iter(|| {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let segment = modules::handle("char", &args);
segment.output()
});
}
#[bench]
fn dir_section_bench(b: &mut Bencher) {
b.iter(|| {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let segment = modules::handle("dir", &args);
segment.output()
});
}
#[bench]
fn line_break_section_bench(b: &mut Bencher) {
b.iter(|| {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let segment = modules::handle("line_break", &args);
segment.output()
});
}
#[bench]
fn nodejs_section_bench(b: &mut Bencher) {
b.iter(|| {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let segment = modules::handle("nodejs", &args);
segment.output()
});
}
}
+47
View File
@@ -0,0 +1,47 @@
#[macro_use]
extern crate criterion;
use criterion::Criterion;
use clap::{App, Arg};
use starship::modules;
use std::path::Path;
fn char_segment(c: &mut Criterion) {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let path = Path::new("~");
c.bench_function("char segment", move |b| {
b.iter(|| modules::handle("char", &path, &args))
});
}
fn dir_segment(c: &mut Criterion) {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let path = Path::new("~");
c.bench_function("dir segment", move |b| {
b.iter(|| modules::handle("dir", &path, &args))
});
}
fn line_break_segment(c: &mut Criterion) {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let path = Path::new("~");
c.bench_function("line break segment", move |b| {
b.iter(|| modules::handle("line_break", &path, &args))
});
}
criterion_group!(benches, dir_segment, char_segment, line_break_segment);
criterion_main!(benches);