mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 17:00:18 +00:00
Use milliseconds for small durations, closes #10
This commit is contained in:
1 parent
2ba316063a
commit
c432fecd36
3 files changed
+29
-3
No files matched your search
@@ -5,6 +5,7 @@ use std::time::Instant;
|
|||||||
use ansi_term::Colour::{Cyan, Green, White, Yellow};
|
use ansi_term::Colour::{Cyan, Green, White, Yellow};
|
||||||
|
|
||||||
use hyperfine::internal::{get_progress_bar, HyperfineOptions, Second, Warnings, MIN_EXECUTION_TIME};
|
use hyperfine::internal::{get_progress_bar, HyperfineOptions, Second, Warnings, MIN_EXECUTION_TIME};
|
||||||
|
use hyperfine::format::{format_duration, format_duration_unit, Unit};
|
||||||
use hyperfine::statistics::mean;
|
use hyperfine::statistics::mean;
|
||||||
|
|
||||||
/// Results from timing a single shell command
|
/// Results from timing a single shell command
|
||||||
@@ -145,8 +146,8 @@ pub fn run_benchmark(
|
|||||||
for _ in 0..count_remaining {
|
for _ in 0..count_remaining {
|
||||||
let msg = {
|
let msg = {
|
||||||
let execution_times = results.iter().map(&get_execution_time);
|
let execution_times = results.iter().map(&get_execution_time);
|
||||||
let mean = format!("{:.3} s", mean(execution_times));
|
let mean = format_duration(mean(execution_times), Unit::Auto);
|
||||||
format!("Current estimate: {:.3}", Green.paint(mean))
|
format!("Current estimate: {}", Green.paint(mean))
|
||||||
};
|
};
|
||||||
bar.set_message(&msg);
|
bar.set_message(&msg);
|
||||||
|
|
||||||
@@ -167,7 +168,9 @@ pub fn run_benchmark(
|
|||||||
let stddev = (t2_mean - t_mean.powi(2)).sqrt();
|
let stddev = (t2_mean - t_mean.powi(2)).sqrt();
|
||||||
|
|
||||||
// Formatting and console output
|
// Formatting and console output
|
||||||
let time_fmt = format!("{:.3} s ± {:.3} s", t_mean, stddev);
|
let (mean_str, unit_mean) = format_duration_unit(t_mean, Unit::Auto);
|
||||||
|
let stddev_str = format_duration(stddev, unit_mean);
|
||||||
|
let time_fmt = format!("{} ± {}", mean_str, stddev_str);
|
||||||
|
|
||||||
println!(" Time: {}", Green.paint(time_fmt));
|
println!(" Time: {}", Green.paint(time_fmt));
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
use hyperfine::internal::Second;
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
pub enum Unit {
|
||||||
|
Auto,
|
||||||
|
Second,
|
||||||
|
MilliSecond,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format_duration(duration: Second, unit: Unit) -> String {
|
||||||
|
match format_duration_unit(duration, unit) {
|
||||||
|
(duration_fmt, _) => duration_fmt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format_duration_unit(duration: Second, unit: Unit) -> (String, Unit) {
|
||||||
|
if (duration < 1.0 && unit == Unit::Auto) || unit == Unit::MilliSecond {
|
||||||
|
(format!("{:.1} ms", duration * 1e3), Unit::MilliSecond)
|
||||||
|
} else {
|
||||||
|
(format!("{:.3} s", duration), Unit::Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
pub mod benchmark;
|
pub mod benchmark;
|
||||||
|
pub mod format;
|
||||||
pub mod internal;
|
pub mod internal;
|
||||||
pub mod statistics;
|
pub mod statistics;
|
||||||
Reference in new issue
Block a user