mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 07:46:28 +00:00
022e0002e4
* Create "context" to contain run details * Use context in tests and benchmarks
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
#[macro_use]
|
|
extern crate criterion;
|
|
|
|
use criterion::Criterion;
|
|
|
|
use clap::{App, Arg};
|
|
use starship::context::Context;
|
|
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"]);
|
|
let context = Context::new_with_dir(args, "~");
|
|
|
|
c.bench_function("char segment", move |b| {
|
|
b.iter(|| modules::handle("char", &context))
|
|
});
|
|
}
|
|
|
|
fn dir_segment(c: &mut Criterion) {
|
|
let args = App::new("starship")
|
|
.arg(Arg::with_name("status_code"))
|
|
.get_matches_from(vec!["starship", "0"]);
|
|
let context = Context::new_with_dir(args, "~");
|
|
|
|
c.bench_function("dir segment", move |b| {
|
|
b.iter(|| modules::handle("dir", &context))
|
|
});
|
|
}
|
|
|
|
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 context = Context::new_with_dir(args, "~");
|
|
|
|
c.bench_function("line break segment", move |b| {
|
|
b.iter(|| modules::handle("line_break", &context))
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, dir_segment, char_segment, line_break_segment);
|
|
criterion_main!(benches);
|