mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-26 18:10:05 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5f58651a1 |
No files matched your search
@@ -266,7 +266,7 @@ impl Executor for ShellExecutor<'_> {
|
|||||||
time_wall_clock: measurements.time_wall_clock_mean(),
|
time_wall_clock: measurements.time_wall_clock_mean(),
|
||||||
time_user: measurements.time_user_mean(),
|
time_user: measurements.time_user_mean(),
|
||||||
time_system: measurements.time_system_mean(),
|
time_system: measurements.time_system_mean(),
|
||||||
peak_memory_usage: Information::zero(),
|
peak_memory_usage: measurements.peak_memory_usage_mean(),
|
||||||
exit_status: ExitStatus::default(),
|
exit_status: ExitStatus::default(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::process::ExitStatus;
|
use std::process::ExitStatus;
|
||||||
|
|
||||||
use crate::quantity::statistics::{max, mean, median, min, modified_zscores, standard_deviation};
|
use crate::quantity::statistics::{max, mean, median, min, modified_zscores, standard_deviation};
|
||||||
use crate::quantity::{second, Information, Time};
|
use crate::quantity::{Information, Time};
|
||||||
|
|
||||||
/// Performance measurements and exit status from running a single command
|
/// Performance measurements and exit status from running a single command
|
||||||
#[derive(Debug, Default, Copy, Clone)]
|
#[derive(Debug, Default, Copy, Clone)]
|
||||||
@@ -77,12 +77,7 @@ impl Measurements {
|
|||||||
|
|
||||||
/// Compute modified Z-scores for the wall clock times.
|
/// Compute modified Z-scores for the wall clock times.
|
||||||
pub fn modified_zscores(&self) -> Vec<f64> {
|
pub fn modified_zscores(&self) -> Vec<f64> {
|
||||||
modified_zscores(
|
modified_zscores(&self.wall_clock_times().collect::<Vec<_>>())
|
||||||
&self
|
|
||||||
.wall_clock_times()
|
|
||||||
.map(|t| t.get::<second>())
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The average user time.
|
/// The average user time.
|
||||||
@@ -94,4 +89,8 @@ impl Measurements {
|
|||||||
pub fn time_system_mean(&self) -> Time {
|
pub fn time_system_mean(&self) -> Time {
|
||||||
mean(self.measurements.iter().map(|m| m.time_system))
|
mean(self.measurements.iter().map(|m| m.time_system))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn peak_memory_usage_mean(&self) -> Information {
|
||||||
|
mean(self.measurements.iter().map(|m| m.peak_memory_usage))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+5
-1
@@ -97,10 +97,14 @@ impl<'a> Command<'a> {
|
|||||||
&self.parameters
|
&self.parameters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_parameter_unused(&self, parameter: &str) -> bool {
|
||||||
|
!self.expression.contains(&format!("{{{parameter}}}"))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_unused_parameters(&self) -> impl Iterator<Item = &(&'a str, ParameterValue)> {
|
pub fn get_unused_parameters(&self) -> impl Iterator<Item = &(&'a str, ParameterValue)> {
|
||||||
self.parameters
|
self.parameters
|
||||||
.iter()
|
.iter()
|
||||||
.filter(move |(parameter, _)| !self.expression.contains(&format!("{{{parameter}}}")))
|
.filter(move |(parameter, _)| self.is_parameter_unused(parameter))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_parameters_in(&self, original: &str) -> String {
|
fn replace_parameters_in(&self, original: &str) -> String {
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ pub const OUTLIER_THRESHOLD: f64 = 1.4826 * 10.0;
|
|||||||
/// modified Z-score that is larger than `OUTLIER_THRESHOLD`.
|
/// modified Z-score that is larger than `OUTLIER_THRESHOLD`.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn num_outliers(xs: &[f64]) -> usize {
|
pub fn num_outliers(xs: &[f64]) -> usize {
|
||||||
use crate::quantity::statistics::modified_zscores;
|
use crate::quantity::statistics::modified_zscores_f64;
|
||||||
|
|
||||||
if xs.is_empty() {
|
if xs.is_empty() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let scores = modified_zscores(xs);
|
let scores = modified_zscores_f64(xs);
|
||||||
scores
|
scores
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&s| s.abs() > OUTLIER_THRESHOLD)
|
.filter(|&&s| s.abs() > OUTLIER_THRESHOLD)
|
||||||
|
|||||||
+1
-3
@@ -4,9 +4,7 @@ pub use uom::num_traits::Zero;
|
|||||||
pub use uom::si::f64::{Information, Ratio, Time};
|
pub use uom::si::f64::{Information, Ratio, Time};
|
||||||
pub use uom::si::information::byte;
|
pub use uom::si::information::byte;
|
||||||
pub use uom::si::ratio::ratio;
|
pub use uom::si::ratio::ratio;
|
||||||
#[cfg(any(not(windows), test))]
|
pub use uom::si::time::{microsecond, nanosecond, second};
|
||||||
pub use uom::si::time::microsecond;
|
|
||||||
pub use uom::si::time::{nanosecond, second};
|
|
||||||
|
|
||||||
pub use units::TimeUnit;
|
pub use units::TimeUnit;
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ pub fn standard_deviation<Q: UnsafeRawValue>(values: &[Q], mean: Q) -> Q {
|
|||||||
///
|
///
|
||||||
/// References:
|
/// References:
|
||||||
/// - <https://en.wikipedia.org/wiki/Median_absolute_deviation>
|
/// - <https://en.wikipedia.org/wiki/Median_absolute_deviation>
|
||||||
pub fn modified_zscores(xs: &[f64]) -> Vec<f64> {
|
pub fn modified_zscores_f64(xs: &[f64]) -> Vec<f64> {
|
||||||
assert!(!xs.is_empty());
|
assert!(!xs.is_empty());
|
||||||
|
|
||||||
// Compute sample median:
|
// Compute sample median:
|
||||||
@@ -131,6 +131,11 @@ pub fn modified_zscores(xs: &[f64]) -> Vec<f64> {
|
|||||||
xs.iter().map(|&x| (x - x_median) / mad).collect()
|
xs.iter().map(|&x| (x - x_median) / mad).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn modified_zscores<Q: UnsafeRawValue>(values: &[Q]) -> Vec<f64> {
|
||||||
|
let values: Vec<_> = values.iter().map(|q| q.unsafe_raw_value()).collect();
|
||||||
|
modified_zscores_f64(&values)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ use windows_sys::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::quantity::{nanosecond, Information, Time, Zero};
|
use crate::quantity::{microsecond, Information, Time, Zero};
|
||||||
|
|
||||||
|
const HUNDRED_NS_PER_MS: i64 = 10;
|
||||||
|
|
||||||
#[cfg(not(feature = "windows_process_extensions_main_thread_handle"))]
|
#[cfg(not(feature = "windows_process_extensions_main_thread_handle"))]
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
@@ -106,14 +108,17 @@ impl CPUTimer {
|
|||||||
// The `TotalUserTime` is "The total amount of user-mode execution time for
|
// The `TotalUserTime` is "The total amount of user-mode execution time for
|
||||||
// all active processes associated with the job, as well as all terminated processes no
|
// all active processes associated with the job, as well as all terminated processes no
|
||||||
// longer associated with the job, in 100-nanosecond ticks."
|
// longer associated with the job, in 100-nanosecond ticks."
|
||||||
let user_time = Time::new::<nanosecond>((job_object_info.TotalUserTime as f64) * 100.0);
|
let user: i64 = job_object_info.TotalUserTime / HUNDRED_NS_PER_MS;
|
||||||
|
|
||||||
// The `TotalKernelTime` is "The total amount of kernel-mode execution time
|
// The `TotalKernelTime` is "The total amount of kernel-mode execution time
|
||||||
// for all active processes associated with the job, as well as all terminated
|
// for all active processes associated with the job, as well as all terminated
|
||||||
// processes no longer associated with the job, in 100-nanosecond ticks."
|
// processes no longer associated with the job, in 100-nanosecond ticks."
|
||||||
let system_time =
|
let kernel: i64 = job_object_info.TotalKernelTime / HUNDRED_NS_PER_MS;
|
||||||
Time::new::<nanosecond>((job_object_info.TotalKernelTime as f64) * 100.0);
|
(
|
||||||
(user_time, system_time, Information::zero())
|
Time::new::<microsecond>(user as f64),
|
||||||
|
Time::new::<microsecond>(kernel as f64),
|
||||||
|
Information::zero(),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
(Time::zero(), Time::zero(), Information::zero())
|
(Time::zero(), Time::zero(), Information::zero())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user