Skip to content

Commit

Permalink
Implemented benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
carlolars authored and andy-5 committed Oct 11, 2019
1 parent 1604839 commit 09fefcf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@ cargo test -- --test-threads=1
cargo test test -- --test-threads=1
# Run only integration tests
cargo test integration -- --test-threads=1
# Run benchmarks (requires nightly toolchain!)
cargo +nightly bench
```
60 changes: 60 additions & 0 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#![feature(test)]
extern crate test;

#[cfg(test)]
mod bench {
use std::env;
use std::process::Command;
use test::Bencher;

#[bench]
fn no_translation(b: &mut Bencher) {
b.iter(|| {
Command::new("wslgit")
.args(&["--version"])
.env("WSLGIT_USE_INTERACTIVE_SHELL", "false")
.output()
})
}

#[bench]
fn translate_absolute_argument(b: &mut Bencher) {
let p = env::current_dir()
.unwrap()
.as_path()
.join("src\\main.rs")
.as_path()
.to_string_lossy()
.into_owned();
let file_path = p.as_str();

b.iter(|| {
Command::new("wslgit")
.args(&["log", "-n1", "--oneline", "--", file_path])
.env("WSLGIT_USE_INTERACTIVE_SHELL", "false")
.output()
})
}

#[bench]
fn translate_relative_argument(b: &mut Bencher) {
let file_path = "src\\main.rs";

b.iter(|| {
Command::new("wslgit")
.args(&["log", "-n1", "--oneline", "--", file_path])
.env("WSLGIT_USE_INTERACTIVE_SHELL", "false")
.output()
})
}

#[bench]
fn translate_output(b: &mut Bencher) {
b.iter(|| {
Command::new("wslgit")
.args(&["rev-parse", "--show-toplevel"])
.env("WSLGIT_USE_INTERACTIVE_SHELL", "false")
.output()
})
}
}

0 comments on commit 09fefcf

Please sign in to comment.