Skip to content
Myr

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

4 files+260 added−0 removed

added:src/main.rs+82 added
1extern crate ansi_term;2extern crate clap;34use std::process::{Command, Stdio};5use std::time::Instant;6use std::io::{stdout, Write};78use ansi_term::Colour::{Cyan, Green, Red};9use clap::{App, AppSettings, Arg};1011struct CmdResult {12 duration_sec: f64,13 success: bool,14}1516impl CmdResult {17 fn new(duration_sec: f64, success: bool) -> CmdResult {18 CmdResult {19 duration_sec,20 success,21 }22 }23}2425fn run_shell_command(shell_cmd: &str) -> CmdResult {26 let start = Instant::now();2728 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");3536 let duration = start.elapsed();3738 let duration_sec = duration.as_secs() as f64 + duration.subsec_nanos() as f64 * 1e-9;3940 CmdResult::new(duration_sec, status.success())41}4243fn 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();5657 let commands = matches.values_of("command").unwrap();58 for cmd in commands {59 println!("Command '{}'", Cyan.paint(cmd));60 print!("Running benchmark ");6162 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");7071 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));7576 if !results.iter().all(|r| r.success) {77 println!("{}", Red.paint("Warning: non-zero exit code"));78 };7980 println!();81 }82}
added:.gitignore+3 added
12/target/3**/*.rs.bk
added:Cargo.lock+162 added
1[[package]]2name = "ansi_term"3version = "0.9.0"4source = "registry+https://github.com/rust-lang/crates.io-index"56[[package]]7name = "ansi_term"8version = "0.10.2"9source = "registry+https://github.com/rust-lang/crates.io-index"1011[[package]]12name = "atty"13version = "0.2.6"14source = "registry+https://github.com/rust-lang/crates.io-index"15dependencies = [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]2021[[package]]22name = "bitflags"23version = "1.0.1"24source = "registry+https://github.com/rust-lang/crates.io-index"2526[[package]]27name = "clap"28version = "2.29.1"29source = "registry+https://github.com/rust-lang/crates.io-index"30dependencies = [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]3940[[package]]41name = "hyperfine"42version = "0.1.0"43dependencies = [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]4748[[package]]49name = "kernel32-sys"50version = "0.2.2"51source = "registry+https://github.com/rust-lang/crates.io-index"52dependencies = [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]5657[[package]]58name = "libc"59version = "0.2.36"60source = "registry+https://github.com/rust-lang/crates.io-index"6162[[package]]63name = "redox_syscall"64version = "0.1.37"65source = "registry+https://github.com/rust-lang/crates.io-index"6667[[package]]68name = "redox_termios"69version = "0.1.1"70source = "registry+https://github.com/rust-lang/crates.io-index"71dependencies = [72 "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",73]7475[[package]]76name = "strsim"77version = "0.6.0"78source = "registry+https://github.com/rust-lang/crates.io-index"7980[[package]]81name = "term_size"82version = "0.3.1"83source = "registry+https://github.com/rust-lang/crates.io-index"84dependencies = [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]8990[[package]]91name = "termion"92version = "1.5.1"93source = "registry+https://github.com/rust-lang/crates.io-index"94dependencies = [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]99100[[package]]101name = "textwrap"102version = "0.9.0"103source = "registry+https://github.com/rust-lang/crates.io-index"104dependencies = [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]108109[[package]]110name = "unicode-width"111version = "0.1.4"112source = "registry+https://github.com/rust-lang/crates.io-index"113114[[package]]115name = "winapi"116version = "0.2.8"117source = "registry+https://github.com/rust-lang/crates.io-index"118119[[package]]120name = "winapi"121version = "0.3.3"122source = "registry+https://github.com/rust-lang/crates.io-index"123dependencies = [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]127128[[package]]129name = "winapi-build"130version = "0.1.1"131source = "registry+https://github.com/rust-lang/crates.io-index"132133[[package]]134name = "winapi-i686-pc-windows-gnu"135version = "0.3.2"136source = "registry+https://github.com/rust-lang/crates.io-index"137138[[package]]139name = "winapi-x86_64-pc-windows-gnu"140version = "0.3.2"141source = "registry+https://github.com/rust-lang/crates.io-index"142143[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