Initial commit
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · the first commit · Browse files · 4 files·+260 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+260 added−0 removed
- other:+260 added−0 removed
Provenance
- Commit
a658ab8- Tree
b78a4b5- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>
4 files changed+260 added−0 removed
added:src/main.rs+82 added
1+extern crate ansi_term;2+extern crate clap;3+4+use std::process::{Command, Stdio};5+use std::time::Instant;6+use std::io::{stdout, Write};7+8+use ansi_term::Colour::{Cyan, Green, Red};9+use clap::{App, AppSettings, Arg};10+11+struct CmdResult {12+ duration_sec: f64,13+ success: bool,14+}15+16+impl CmdResult {17+ fn new(duration_sec: f64, success: bool) -> CmdResult {18+ CmdResult {19+ duration_sec,20+ success,21+ }22+ }23+}24+25+fn run_shell_command(shell_cmd: &str) -> CmdResult {26+ let start = Instant::now();27+28+ let status = Command::new("sh")29+ .arg("-c")30+ .arg(shell_cmd)31+ .stdout(Stdio::null())32+ .stderr(Stdio::null())33+ .status()34+ .expect("failed to execute process");35+36+ let duration = start.elapsed();37+38+ let duration_sec = duration.as_secs() as f64 + duration.subsec_nanos() as f64 * 1e-9;39+40+ CmdResult::new(duration_sec, status.success())41+}42+43+fn main() {44+ let matches = App::new("hyperfine")45+ .global_settings(&[AppSettings::ColoredHelp])46+ .version("0.1")47+ .about("A command-line benchmarking tool")48+ .author("David Peter <mail@david-peter.de>")49+ .arg(50+ Arg::with_name("command")51+ .help("Command to benchmark")52+ .required(true)53+ .multiple(true),54+ )55+ .get_matches();56+57+ let commands = matches.values_of("command").unwrap();58+ for cmd in commands {59+ println!("Command '{}'", Cyan.paint(cmd));60+ print!("Running benchmark ");61+62+ let mut results = vec![];63+ for _ in 1..10 {64+ print!(".");65+ let res = run_shell_command(cmd);66+ results.push(res);67+ let _ = stdout().flush();68+ }69+ println!(" done");70+71+ let duration_sum: f64 = results.iter().map(|r| r.duration_sec).sum();72+ let duration_mean = duration_sum / (results.len() as f64);73+ let duration_str = format!("{:.3} s", duration_mean);74+ println!(" Time: {:.3}", Green.paint(duration_str));75+76+ if !results.iter().all(|r| r.success) {77+ println!("{}", Red.paint("Warning: non-zero exit code"));78+ };79+80+ println!();81+ }82+}added:.gitignore+3 added
1+2+/target/3+**/*.rs.bkadded:Cargo.lock+162 added
1+[[package]]2+name = "ansi_term"3+version = "0.9.0"4+source = "registry+https://github.com/rust-lang/crates.io-index"5+6+[[package]]7+name = "ansi_term"8+version = "0.10.2"9+source = "registry+https://github.com/rust-lang/crates.io-index"10+11+[[package]]12+name = "atty"13+version = "0.2.6"14+source = "registry+https://github.com/rust-lang/crates.io-index"15+dependencies = [16+ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",17+ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",18+ "winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",19+]20+21+[[package]]22+name = "bitflags"23+version = "1.0.1"24+source = "registry+https://github.com/rust-lang/crates.io-index"25+26+[[package]]27+name = "clap"28+version = "2.29.1"29+source = "registry+https://github.com/rust-lang/crates.io-index"30+dependencies = [31+ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",32+ "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",33+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",34+ "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",35+ "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",36+ "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",37+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",38+]39+40+[[package]]41+name = "hyperfine"42+version = "0.1.0"43+dependencies = [44+ "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",45+ "clap 2.29.1 (registry+https://github.com/rust-lang/crates.io-index)",46+]47+48+[[package]]49+name = "kernel32-sys"50+version = "0.2.2"51+source = "registry+https://github.com/rust-lang/crates.io-index"52+dependencies = [53+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",54+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",55+]56+57+[[package]]58+name = "libc"59+version = "0.2.36"60+source = "registry+https://github.com/rust-lang/crates.io-index"61+62+[[package]]63+name = "redox_syscall"64+version = "0.1.37"65+source = "registry+https://github.com/rust-lang/crates.io-index"66+67+[[package]]68+name = "redox_termios"69+version = "0.1.1"70+source = "registry+https://github.com/rust-lang/crates.io-index"71+dependencies = [72+ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",73+]74+75+[[package]]76+name = "strsim"77+version = "0.6.0"78+source = "registry+https://github.com/rust-lang/crates.io-index"79+80+[[package]]81+name = "term_size"82+version = "0.3.1"83+source = "registry+https://github.com/rust-lang/crates.io-index"84+dependencies = [85+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",86+ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",87+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",88+]89+90+[[package]]91+name = "termion"92+version = "1.5.1"93+source = "registry+https://github.com/rust-lang/crates.io-index"94+dependencies = [95+ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",96+ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",97+ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",98+]99+100+[[package]]101+name = "textwrap"102+version = "0.9.0"103+source = "registry+https://github.com/rust-lang/crates.io-index"104+dependencies = [105+ "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",106+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",107+]108+109+[[package]]110+name = "unicode-width"111+version = "0.1.4"112+source = "registry+https://github.com/rust-lang/crates.io-index"113+114+[[package]]115+name = "winapi"116+version = "0.2.8"117+source = "registry+https://github.com/rust-lang/crates.io-index"118+119+[[package]]120+name = "winapi"121+version = "0.3.3"122+source = "registry+https://github.com/rust-lang/crates.io-index"123+dependencies = [124+ "winapi-i686-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",125+ "winapi-x86_64-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",126+]127+128+[[package]]129+name = "winapi-build"130+version = "0.1.1"131+source = "registry+https://github.com/rust-lang/crates.io-index"132+133+[[package]]134+name = "winapi-i686-pc-windows-gnu"135+version = "0.3.2"136+source = "registry+https://github.com/rust-lang/crates.io-index"137+138+[[package]]139+name = "winapi-x86_64-pc-windows-gnu"140+version = "0.3.2"141+source = "registry+https://github.com/rust-lang/crates.io-index"142+143+[metadata]144+"checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455"145+"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"146+"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859"147+"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"148+"checksum clap 2.29.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8f4a2b3bb7ef3c672d7c13d15613211d5a6976b6892c598b0fcb5d40765f19c2"149+"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"150+"checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121"151+"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"152+"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"153+"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"154+"checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327"155+"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"156+"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693"157+"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"158+"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"159+"checksum winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b09fb3b6f248ea4cd42c9a65113a847d612e17505d6ebd1f7357ad68a8bf8693"160+"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"161+"checksum winapi-i686-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ec6667f60c23eca65c561e63a13d81b44234c2e38a6b6c959025ee907ec614cc"162+"checksum winapi-x86_64-pc-windows-gnu 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98f12c52b2630cd05d2c3ffd8e008f7f48252c042b4871c72aed9dc733b96668"added:Cargo.toml+13 added
12345678910111213[package]name = "hyperfine"version = "0.1.0"authors = ["David Peter <mail@david-peter.de>"]
[dependencies]ansi_term = "0.9"
[dependencies.clap]version = "2"default-features = false
features = ["suggestions", "color", "wrap_help"]