2019-04-16 19:20:00 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate criterion;
|
|
|
|
|
|
|
|
use criterion::Criterion;
|
|
|
|
|
|
|
|
use clap::{App, Arg};
|
2019-04-19 20:57:14 +00:00
|
|
|
use starship::context::Context;
|
2019-04-16 19:20:00 +00:00
|
|
|
use starship::modules;
|
2019-05-10 03:51:50 +00:00
|
|
|
use std::fs;
|
|
|
|
use tempfile::TempDir;
|
2019-04-16 19:20:00 +00:00
|
|
|
|
|
|
|
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 20:57:14 +00:00
|
|
|
let context = Context::new_with_dir(args, "~");
|
2019-04-16 19:20:00 +00:00
|
|
|
|
|
|
|
c.bench_function("char segment", move |b| {
|
2019-04-19 20:57:14 +00:00
|
|
|
b.iter(|| modules::handle("char", &context))
|
2019-04-16 19:20:00 +00: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 20:57:14 +00:00
|
|
|
let context = Context::new_with_dir(args, "~");
|
2019-04-16 19:20:00 +00:00
|
|
|
|
|
|
|
c.bench_function("dir segment", move |b| {
|
2019-04-19 20:57:14 +00:00
|
|
|
b.iter(|| modules::handle("dir", &context))
|
2019-04-16 19:20:00 +00: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 20:57:14 +00:00
|
|
|
let context = Context::new_with_dir(args, "~");
|
2019-04-16 19:20:00 +00:00
|
|
|
|
|
|
|
c.bench_function("line break segment", move |b| {
|
2019-04-19 20:57:14 +00:00
|
|
|
b.iter(|| modules::handle("line_break", &context))
|
2019-04-16 19:20:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-10 03:51:50 +00:00
|
|
|
fn git_branch_segment(c: &mut Criterion) {
|
|
|
|
let tmp_dir = TempDir::new().unwrap();
|
|
|
|
let repo_dir = tmp_dir.path().join("rocket-controls");
|
|
|
|
fs::create_dir(&repo_dir).unwrap();
|
|
|
|
|
|
|
|
git2::Repository::init(&repo_dir).unwrap();
|
|
|
|
|
|
|
|
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("git_branch segment", move |b| {
|
|
|
|
b.iter(|| modules::handle("git_branch", &context))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(
|
|
|
|
benches,
|
|
|
|
char_segment,
|
|
|
|
dir_segment,
|
|
|
|
line_break_segment,
|
|
|
|
git_branch_segment
|
|
|
|
);
|
2019-04-16 19:20:00 +00:00
|
|
|
criterion_main!(benches);
|