diff options
author | Matan Kushner <hello@matchai.me> | 2019-04-04 16:59:03 -0400 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-04-04 16:59:03 -0400 |
commit | 52a529c62736d5186453f095b15b0ce038ec72a7 (patch) | |
tree | 7562f39cbb330a2056a4a0eddad82f2168fe3f16 | |
parent | 7136059dcd4d3b3fe6857dcf0542bd850a50d813 (diff) |
Add basic benchmarks
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | benches/benchmarks.rs | 45 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/print.rs | 2 |
5 files changed, 50 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock index 3ca0b8a63..f4682a410 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "ansi_term" version = "0.11.0" diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs new file mode 100644 index 000000000..42a763b11 --- /dev/null +++ b/benches/benchmarks.rs @@ -0,0 +1,45 @@ +#![feature(test)] + +extern crate test; + +#[cfg(test)] +mod tests { + use starship::{modules, print}; + use test::Bencher; + use clap::{App, Arg}; + + #[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); + print::print_segment(segment) + }); + } + + #[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); + print::print_segment(segment) + }); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 000000000..ccfc24c86 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +pub mod modules; +pub mod print; diff --git a/src/main.rs b/src/main.rs index f1de02bbe..d6694e3dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ #[macro_use] extern crate clap; -extern crate ansi_term; mod modules; mod print; diff --git a/src/print.rs b/src/print.rs index 8eb526698..c2951967d 100644 --- a/src/print.rs +++ b/src/print.rs @@ -11,7 +11,7 @@ pub fn prompt(args: ArgMatches) { } } -fn print_segment(segment: Segment) { +pub fn print_segment(segment: Segment) { let Segment { prefix, value, |