1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#[macro_use]
extern crate criterion;
use criterion::Criterion;
use clap::{App, Arg};
use starship::context::Context;
use starship::modules;
use std::fs;
use tempfile::TempDir;
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))
});
}
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
);
criterion_main!(benches);
|