mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Move user and system time
This commit is contained in:
1 parent
14d773998a
commit
50232feb22
6 files changed
+106
-42
No files matched your search
@@ -10,9 +10,14 @@ use crate::util::{
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
|
||||
pub struct BenchmarkRun {
|
||||
/// Wall clock time measurement
|
||||
pub wall_clock_time: Second,
|
||||
// user_time: Second,
|
||||
// system_time: Second,
|
||||
|
||||
/// Time spent in user mode
|
||||
pub user_time: Second,
|
||||
|
||||
/// Time spent in kernel mode
|
||||
pub system_time: Second,
|
||||
}
|
||||
|
||||
use crate::benchmark::measurement::Measurements;
|
||||
@@ -37,12 +42,6 @@ pub struct BenchmarkResult {
|
||||
/// The full command line, including parameters not used in the command template.
|
||||
pub command_with_unused_parameters: String,
|
||||
|
||||
/// Time spent in user mode
|
||||
pub user: f64,
|
||||
|
||||
/// Time spent in kernel mode
|
||||
pub system: f64,
|
||||
|
||||
/// All run time measurements
|
||||
pub runs: Vec<BenchmarkRun>,
|
||||
|
||||
@@ -157,4 +156,24 @@ impl BenchmarkResult {
|
||||
pub fn max(&self) -> Second {
|
||||
max(&self.wall_clock_times())
|
||||
}
|
||||
|
||||
pub fn user_mean(&self) -> Second {
|
||||
mean(
|
||||
&self
|
||||
.runs
|
||||
.iter()
|
||||
.map(|run| run.user_time)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn system_mean(&self) -> Second {
|
||||
mean(
|
||||
&self
|
||||
.runs
|
||||
.iter()
|
||||
.map(|run| run.system_time)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -490,12 +490,13 @@ impl<'a> Benchmark<'a> {
|
||||
Ok(BenchmarkResult {
|
||||
command: self.command.get_name(),
|
||||
command_with_unused_parameters: self.command.get_name_with_unused_parameters(),
|
||||
user: user_mean,
|
||||
system: system_mean,
|
||||
runs: times_real
|
||||
.iter()
|
||||
.map(|t| BenchmarkRun {
|
||||
wall_clock_time: *t,
|
||||
.zip(times_user.iter().zip(times_system.iter()))
|
||||
.map(|(wall_clock_time, (user_time, system_time))| BenchmarkRun {
|
||||
wall_clock_time: *wall_clock_time,
|
||||
user_time: *user_time,
|
||||
system_time: *system_time,
|
||||
})
|
||||
.collect(),
|
||||
memory_usage_byte: Some(memory_usage_byte),
|
||||
|
||||
@@ -152,10 +152,10 @@ fn create_result(name: &str, mean: f64) -> BenchmarkResult {
|
||||
BenchmarkResult {
|
||||
command: name.into(),
|
||||
command_with_unused_parameters: name.into(),
|
||||
user: mean,
|
||||
system: 0.0,
|
||||
runs: vec![BenchmarkRun {
|
||||
wall_clock_time: mean,
|
||||
user_time: mean,
|
||||
system_time: 0.,
|
||||
}],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: Vec::new(),
|
||||
|
||||
@@ -205,11 +205,13 @@ fn generate_results(args: &[&'static str]) -> Result<Vec<BenchmarkResult>> {
|
||||
fn scheduler_basic() -> Result<()> {
|
||||
insta::assert_yaml_snapshot!(generate_results(&["--runs=2", "sleep 0.123", "sleep 0.456"])?, @r#"
|
||||
- command: sleep 0.123
|
||||
user: 0
|
||||
system: 0
|
||||
runs:
|
||||
- wall_clock_time: 0.123
|
||||
user_time: 0
|
||||
system_time: 0
|
||||
- wall_clock_time: 0.123
|
||||
user_time: 0
|
||||
system_time: 0
|
||||
memory_usage_byte:
|
||||
- 0
|
||||
- 0
|
||||
@@ -217,11 +219,13 @@ fn scheduler_basic() -> Result<()> {
|
||||
- 0
|
||||
- 0
|
||||
- command: sleep 0.456
|
||||
user: 0
|
||||
system: 0
|
||||
runs:
|
||||
- wall_clock_time: 0.456
|
||||
user_time: 0
|
||||
system_time: 0
|
||||
- wall_clock_time: 0.456
|
||||
user_time: 0
|
||||
system_time: 0
|
||||
memory_usage_byte:
|
||||
- 0
|
||||
- 0
|
||||
|
||||
Reference in new issue
Block a user