Skip to content

Advanced performance metrics #790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4c173fa
Introduce new BenchmarkRun struct
sharkdp Dec 29, 2024
02a94ec
Move user and system time
sharkdp Dec 29, 2024
3ec42a0
Use wait4 instead of getrusage
sharkdp Dec 29, 2024
ec0df72
Remove command_with_unused_parameters field
sharkdp Dec 29, 2024
fe836e3
Real => wall clock
sharkdp Dec 29, 2024
5bf07c7
Simplify run creation
sharkdp Dec 29, 2024
c92bccc
More simplifications
sharkdp Dec 29, 2024
65bee63
Runs => Measurements
sharkdp Dec 29, 2024
3347893
Units
sharkdp Dec 29, 2024
8936f8e
Switch to unit-safe quantities
sharkdp Dec 30, 2024
c41d660
Unify TimingResult/TimerResult/Measurement
sharkdp Jan 1, 2025
1303507
Rename to exit_code
sharkdp Jan 1, 2025
26fe4a5
Add unit information
sharkdp Jan 1, 2025
456dfd6
Add short unit
sharkdp Jan 4, 2025
2fc989b
Use uom
sharkdp Jan 4, 2025
6c5eae3
Use unit system in unix_timer
sharkdp Jan 4, 2025
d869e8a
Fix Windows timer
sharkdp Jan 4, 2025
3cdae0f
Move quantity module
sharkdp Jan 4, 2025
013754a
Refactoring
sharkdp Jan 5, 2025
9095846
Implement TimeUnit functions via uom
sharkdp Jan 5, 2025
acdbf71
Support minutes and hours
sharkdp Jan 5, 2025
d3d833a
Remove alternative constructors
sharkdp Jan 5, 2025
581c696
TODO comments
sharkdp Jan 5, 2025
3cc3247
Fix Windows includes
sharkdp Jan 5, 2025
f1e201e
Quantity API cleanup
sharkdp Jan 11, 2025
80d2862
Further simplification of the API
sharkdp Jan 11, 2025
fb8ba86
Do not use value_in for CSV export
sharkdp Jan 11, 2025
b7a904f
Represent memory usage as f64 as well
sharkdp Jan 11, 2025
44c8267
Get rid of value_in
sharkdp Jan 11, 2025
aabd8f4
Add test
sharkdp Jan 11, 2025
fede556
Yet another API iteration
sharkdp Jan 11, 2025
32b2295
Make memory units available
sharkdp Jan 11, 2025
db1a107
Unit safe statistics functions
sharkdp Jan 11, 2025
2c6ac67
Cleanup
sharkdp Jan 12, 2025
e406206
Split out statistics module
sharkdp Jan 12, 2025
99c1fdb
Remove statistical dependency
sharkdp Jan 12, 2025
98ed53c
Minor change
sharkdp Jan 12, 2025
a26ab5b
Minor cleanup
sharkdp Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support minutes and hours
  • Loading branch information
sharkdp committed Jan 5, 2025
commit acdbf712df71442f79ebce4c31e63cae2034506e
6 changes: 4 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -260,13 +260,15 @@ fn build_command() -> Command {
.short('u')
.action(ArgAction::Set)
.value_name("UNIT")
.value_parser(["µs", "us", "microsecond", "microseconds", "ms", "millisecond", "milliseconds", "s", "second", "seconds"])
.value_parser(["µs", "us", "microsecond", "microseconds", "ms", "millisecond", "milliseconds", "s", "second", "seconds", "min", "minute", "minutes", "h", "hour", "hours"])
.help("Set the time unit to be used. If the option is not given, the time unit is determined automatically. \
This option affects the standard output as well as all export formats except for CSV and JSON.\n\
Possible values:\n \
* 'µs', 'us', 'microsecond', 'microseconds'\n \
* 'ms', 'millisecond', 'milliseconds'\n \
* 's', 'second', 'seconds'"),
* 's', 'second', 'seconds'\n \
* 'min', 'minute', 'minutes'\n \
* 'h', 'hour', 'hours'"),
)
.arg(
Arg::new("export-asciidoc")
4 changes: 2 additions & 2 deletions src/export/markup.rs
Original file line number Diff line number Diff line change
@@ -111,10 +111,10 @@ impl<T: MarkupExporter> Exporter for T {
fn serialize(
&self,
results: &[BenchmarkResult],
unit: Option<TimeUnit>,
time_unit: Option<TimeUnit>,
sort_order: SortOrder,
) -> Result<Vec<u8>> {
let unit = unit.unwrap_or_else(|| determine_unit_from_results(results));
let unit = time_unit.unwrap_or_else(|| determine_unit_from_results(results));
let entries = relative_speed::compute(results, sort_order);

let table = self.table_results(&entries, unit);
2 changes: 2 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -418,6 +418,8 @@ impl Options {
Some("µs" | "us" | "microsecond" | "microseconds") => Some(TimeUnit::MicroSecond),
Some("ms" | "millisecond" | "milliseconds") => Some(TimeUnit::MilliSecond),
Some("s" | "second" | "seconds") => Some(TimeUnit::Second),
Some("min" | "minute" | "minutes") => Some(TimeUnit::Minute),
Some("h" | "hour" | "hours") => Some(TimeUnit::Hour),
_ => None,
};

3 changes: 2 additions & 1 deletion src/output/format.rs
Original file line number Diff line number Diff line change
@@ -34,7 +34,8 @@ pub fn format_duration_value(duration: Time, time_unit: Option<TimeUnit>) -> (St
TimeUnit::MilliSecond,
)
} else {
(TimeUnit::Second.format(duration), TimeUnit::Second)
let time_unit = time_unit.unwrap_or(TimeUnit::Second);
(time_unit.format(duration), time_unit)
}
}

2 changes: 1 addition & 1 deletion src/quantity.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use uom::{si, Conversion};

pub use uom::si::information::{byte, kibibyte};
pub use uom::si::ratio::ratio;
pub use uom::si::time::{microsecond, millisecond, nanosecond, second};
pub use uom::si::time::{hour, microsecond, millisecond, minute, nanosecond, second};

pub use si::f64::Ratio;
pub use si::f64::Time;
23 changes: 15 additions & 8 deletions src/util/units.rs
Original file line number Diff line number Diff line change
@@ -2,14 +2,16 @@
use std::marker::PhantomData;

use crate::quantity::{microsecond, millisecond, second, Time};
use crate::quantity::{hour, microsecond, millisecond, minute, second, Time};

/// Supported time units
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TimeUnit {
Second,
MilliSecond,
MicroSecond,
MilliSecond,
Second,
Minute,
Hour,
}

struct Dispatcher<U: uom::si::time::Unit + uom::Conversion<f64, T = f64>> {
@@ -41,9 +43,11 @@ impl<U: uom::si::time::Unit + uom::Conversion<f64, T = f64>> UnitImpl for Dispat
impl TimeUnit {
fn dispatch(self) -> Box<dyn UnitImpl> {
match self {
TimeUnit::Second => Box::new(Dispatcher::<second>::new()),
TimeUnit::MilliSecond => Box::new(Dispatcher::<millisecond>::new()),
TimeUnit::MicroSecond => Box::new(Dispatcher::<microsecond>::new()),
TimeUnit::MilliSecond => Box::new(Dispatcher::<millisecond>::new()),
TimeUnit::Second => Box::new(Dispatcher::<second>::new()),
TimeUnit::Minute => Box::new(Dispatcher::<minute>::new()),
TimeUnit::Hour => Box::new(Dispatcher::<hour>::new()),
}
}

@@ -63,6 +67,8 @@ fn test_unit_short_name() {
assert_eq!("s", TimeUnit::Second.short_name());
assert_eq!("ms", TimeUnit::MilliSecond.short_name());
assert_eq!("µs", TimeUnit::MicroSecond.short_name());
assert_eq!("min", TimeUnit::Minute.short_name());
assert_eq!("h", TimeUnit::Hour.short_name());
}

// Note - the values are rounded when formatted.
@@ -71,11 +77,12 @@ fn test_unit_format() {
use crate::quantity::TimeQuantity;

let value = Time::from_seconds(123.456789);
assert_eq!("123.457", TimeUnit::Second.format(value));
assert_eq!("123456.8", TimeUnit::MilliSecond.format(value));

assert_eq!(
"1234.6",
TimeUnit::MicroSecond.format(Time::from_seconds(0.00123456))
);
assert_eq!("123456.8", TimeUnit::MilliSecond.format(value));
assert_eq!("123.457", TimeUnit::Second.format(value));
assert_eq!("2.1", TimeUnit::Minute.format(value));
assert_eq!("0.0", TimeUnit::Hour.format(value));
}