From 52a529c62736d5186453f095b15b0ce038ec72a7 Mon Sep 17 00:00:00 2001 From: Matan Kushner Date: Thu, 4 Apr 2019 16:59:03 -0400 Subject: [PATCH] Add basic benchmarks --- Cargo.lock | 2 ++ benches/benchmarks.rs | 45 +++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 ++ src/main.rs | 1 - src/print.rs | 2 +- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 benches/benchmarks.rs create mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3ca0b8a6..f4682a41 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 00000000..42a763b1 --- /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 00000000..ccfc24c8 --- /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 f1de02bb..d6694e3d 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 8eb52669..c2951967 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,