2019-04-16 21:20:00 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate criterion;
|
|
|
|
|
|
|
|
use criterion::Criterion;
|
|
|
|
|
|
|
|
use clap::{App, Arg};
|
2019-04-19 22:57:14 +02:00
|
|
|
use starship::context::Context;
|
2019-04-16 21:20:00 +02:00
|
|
|
use starship::modules;
|
|
|
|
|
|
|
|
fn char_segment(c: &mut Criterion) {
|
|
|
|
let args = App::new("starship")
|
|
|
|
.arg(Arg::with_name("status_code"))
|
|
|
|
.get_matches_from(vec!["starship", "0"]);
|
2019-04-19 22:57:14 +02:00
|
|
|
let context = Context::new_with_dir(args, "~");
|
2019-04-16 21:20:00 +02:00
|
|
|
|
|
|
|
c.bench_function("char segment", move |b| {
|
2019-04-19 22:57:14 +02:00
|
|
|
b.iter(|| modules::handle("char", &context))
|
2019-04-16 21:20:00 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dir_segment(c: &mut Criterion) {
|
|
|
|
let args = App::new("starship")
|
|
|
|
.arg(Arg::with_name("status_code"))
|
|
|
|
.get_matches_from(vec!["starship", "0"]);
|
2019-04-19 22:57:14 +02:00
|
|
|
let context = Context::new_with_dir(args, "~");
|
2019-04-16 21:20:00 +02:00
|
|
|
|
|
|
|
c.bench_function("dir segment", move |b| {
|
2019-04-19 22:57:14 +02:00
|
|
|
b.iter(|| modules::handle("dir", &context))
|
2019-04-16 21:20:00 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn line_break_segment(c: &mut Criterion) {
|
|
|
|
let args = App::new("starship")
|
|
|
|
.arg(Arg::with_name("status_code"))
|
|
|
|
.get_matches_from(vec!["starship", "0"]);
|
2019-04-19 22:57:14 +02:00
|
|
|
let context = Context::new_with_dir(args, "~");
|
2019-04-16 21:20:00 +02:00
|
|
|
|
|
|
|
c.bench_function("line break segment", move |b| {
|
2019-04-19 22:57:14 +02:00
|
|
|
b.iter(|| modules::handle("line_break", &context))
|
2019-04-16 21:20:00 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, dir_segment, char_segment, line_break_segment);
|
|
|
|
criterion_main!(benches);
|