Skip to content
Myr

Use milliseconds for small durations, closes #10

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent 2ba3160 · Browse files · 3 files+29 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+29 added−3 removed

  • other:+29 added−3 removed

3 files+29 added−3 removed

modified:src/hyperfine/benchmark.rs+6 added-3 removed
3 unmodified lines
45use ansi_term::Colour::{Cyan, Green, White, Yellow};67use hyperfine::internal::{get_progress_bar, HyperfineOptions, Second, Warnings, MIN_EXECUTION_TIME};8use hyperfine::format::{format_duration, format_duration_unit, Unit};9use hyperfine::statistics::mean;1011/// Results from timing a single shell command12pub struct TimingResult {
132 unmodified lines
145 // Gather statistics146 for _ in 0..count_remaining {147 let msg = {148 let execution_times = results.iter().map(&get_execution_time);148 let mean = format!("{:.3} s", mean(execution_times));149 format!("Current estimate: {:.3}", Green.paint(mean))149 let mean = format_duration(mean(execution_times), Unit::Auto);150 format!("Current estimate: {}", Green.paint(mean))151 };152 bar.set_message(&msg);153154 let res = time_shell_command(cmd, options.ignore_failure)?;
12 unmodified lines
167168 let stddev = (t2_mean - t_mean.powi(2)).sqrt();169170 // Formatting and console output170 let time_fmt = format!("{:.3} s ± {:.3} s", t_mean, stddev);171 let (mean_str, unit_mean) = format_duration_unit(t_mean, Unit::Auto);172 let stddev_str = format_duration(stddev, unit_mean);173 let time_fmt = format!("{} ± {}", mean_str, stddev_str);174175 println!(" Time: {}", Green.paint(time_fmt));176177 // Warnings
23 unmodified lines
added:src/hyperfine/format.rs+22 added
1use hyperfine::internal::Second;23#[derive(PartialEq)]4pub enum Unit {5 Auto,6 Second,7 MilliSecond,8}910pub fn format_duration(duration: Second, unit: Unit) -> String {11 match format_duration_unit(duration, unit) {12 (duration_fmt, _) => duration_fmt,13 }14}1516pub fn format_duration_unit(duration: Second, unit: Unit) -> (String, Unit) {17 if (duration < 1.0 && unit == Unit::Auto) || unit == Unit::MilliSecond {18 (format!("{:.1} ms", duration * 1e3), Unit::MilliSecond)19 } else {20 (format!("{:.3} s", duration), Unit::Second)21 }22}
modified:src/hyperfine/mod.rs+1 added
1pub mod benchmark;2pub mod format;3pub mod internal;4pub mod statistics;