Compare commits

...
Author SHA1 Message Date
David Peter ebb3182a6e Fix Windows Clippy warnings 2026-10-05 14:07:39 +02:00
David Peter efd57b3a89 Merge pull request #975 from sharkdp/codex/unified-windows-timer
Unify the Windows CPU timer stop interface
2026-10-05 13:55:36 +02:00
David Peter 580b500052 Merge pull request #973 from sharkdp/dependabot/github_actions/softprops/action-gh-release-3
Bump softprops/action-gh-release from 2 to 3
2026-10-05 13:54:02 +02:00
David Peter ee96552dae Merge pull request #974 from sharkdp/dependabot/github_actions/actions/checkout-7
Bump actions/checkout from 6 to 7
2026-10-05 13:53:45 +02:00
David Peter 6af23bb885 Unify the Windows CPU timer stop interface 2026-10-05 13:51:06 +02:00
David Peter 683885a6c8 Merge pull request #972 from sharkdp/codex/csv-quantity-formatting
Format CSV measurements through FormatQuantity
2026-10-05 13:45:52 +02:00
David Peter 33aafdca07 Merge pull request #971 from sharkdp/codex/typed-relative-speed
Use typed quantities for relative-speed calculations
2026-10-05 13:44:35 +02:00
dependabot[bot] 0e2acb67e5 Bump actions/checkout from 6 to 7
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-10-05 11:42:47 +00:00
dependabot[bot] de0afb81c5 Bump softprops/action-gh-release from 2 to 3
Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2 to 3.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](https://github.com/softprops/action-gh-release/compare/v2...v3)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-version: '3'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-10-05 11:42:43 +00:00
David Peter df49a04a66 Use typed quantities for relative-speed calculations 2026-10-05 13:41:20 +02:00
4 changed files with 38 additions and 51 deletions

No files matched your search

+5 -5
View File
@@ -18,7 +18,7 @@ jobs:
name: Extract crate metadata name: Extract crate metadata
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v7
- name: Extract crate information - name: Extract crate information
id: crate_metadata id: crate_metadata
run: | run: |
@@ -49,7 +49,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
with: with:
components: rustfmt components: rustfmt
- uses: actions/checkout@v6 - uses: actions/checkout@v7
- run: cargo fmt -- --check - run: cargo fmt -- --check
min_version: min_version:
@@ -58,7 +58,7 @@ jobs:
needs: crate_metadata needs: crate_metadata
steps: steps:
- name: Checkout source code - name: Checkout source code
uses: actions/checkout@v6 uses: actions/checkout@v7
- name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }}) - name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
uses: dtolnay/rust-toolchain@master uses: dtolnay/rust-toolchain@master
@@ -96,7 +96,7 @@ jobs:
BUILD_CMD: cargo BUILD_CMD: cargo
steps: steps:
- name: Checkout source code - name: Checkout source code
uses: actions/checkout@v6 uses: actions/checkout@v7
- name: Install prerequisites - name: Install prerequisites
shell: bash shell: bash
@@ -337,7 +337,7 @@ jobs:
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
- name: Publish archives and packages - name: Publish archives and packages
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v3
if: steps.is-release.outputs.IS_RELEASE if: steps.is-release.outputs.IS_RELEASE
with: with:
files: | files: |
+20 -28
View File
@@ -1,8 +1,10 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use super::benchmark_result::BenchmarkResult; use super::benchmark_result::BenchmarkResult;
use crate::options::SortOrder; use crate::{
use crate::quantity::second; options::SortOrder,
quantity::{self, Ratio, Time, Zero},
};
#[derive(Debug)] #[derive(Debug)]
pub struct BenchmarkResultWithRelativeSpeed<'a> { pub struct BenchmarkResultWithRelativeSpeed<'a> {
@@ -16,8 +18,7 @@ pub struct BenchmarkResultWithRelativeSpeed<'a> {
pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering { pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {
l.mean_wall_clock_time() l.mean_wall_clock_time()
.get::<second>() .partial_cmp(&r.mean_wall_clock_time())
.partial_cmp(&r.mean_wall_clock_time().get::<second>())
.unwrap_or(Ordering::Equal) .unwrap_or(Ordering::Equal)
} }
@@ -39,7 +40,7 @@ fn compute_relative_speeds<'a>(
let is_reference = result == reference; let is_reference = result == reference;
let relative_ordering = compare_mean_time(result, reference); let relative_ordering = compare_mean_time(result, reference);
if result.mean_wall_clock_time().get::<second>() == 0.0 { if result.mean_wall_clock_time() == Time::zero() {
return BenchmarkResultWithRelativeSpeed { return BenchmarkResultWithRelativeSpeed {
result, result,
relative_speed: if is_reference { 1.0 } else { f64::INFINITY }, relative_speed: if is_reference { 1.0 } else { f64::INFINITY },
@@ -50,34 +51,25 @@ fn compute_relative_speeds<'a>(
} }
let ratio = match relative_ordering { let ratio = match relative_ordering {
Ordering::Less => { Ordering::Less => reference.mean_wall_clock_time() / result.mean_wall_clock_time(),
reference.mean_wall_clock_time().get::<second>() Ordering::Equal => Ratio::new::<quantity::ratio>(1.0),
/ result.mean_wall_clock_time().get::<second>()
}
Ordering::Equal => 1.0,
Ordering::Greater => { Ordering::Greater => {
result.mean_wall_clock_time().get::<second>() result.mean_wall_clock_time() / reference.mean_wall_clock_time()
/ reference.mean_wall_clock_time().get::<second>()
} }
}; };
// https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas // https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas
// Covariance assumed to be 0, i.e. variables are assumed to be independent // Covariance assumed to be 0, i.e. variables are assumed to be independent
let ratio_stddev = match ( let ratio_stddev = match (
result result.measurements.stddev(),
.measurements reference.measurements.stddev(),
.stddev()
.map(|time| time.get::<second>()),
reference
.measurements
.stddev()
.map(|time| time.get::<second>()),
) { ) {
(Some(result_stddev), Some(fastest_stddev)) => Some( (Some(result_stddev), Some(fastest_stddev)) => Some(
ratio ratio
* ((result_stddev / result.mean_wall_clock_time().get::<second>()).powi(2) * ((result_stddev / result.mean_wall_clock_time())
+ (fastest_stddev / reference.mean_wall_clock_time().get::<second>()) .powi(uom::typenum::P2::new())
.powi(2)) + (fastest_stddev / reference.mean_wall_clock_time())
.powi(uom::typenum::P2::new()))
.sqrt(), .sqrt(),
), ),
_ => None, _ => None,
@@ -85,8 +77,8 @@ fn compute_relative_speeds<'a>(
BenchmarkResultWithRelativeSpeed { BenchmarkResultWithRelativeSpeed {
result, result,
relative_speed: ratio, relative_speed: ratio.get::<quantity::ratio>(),
relative_speed_stddev: ratio_stddev, relative_speed_stddev: ratio_stddev.map(|r| r.get::<quantity::ratio>()),
is_reference, is_reference,
relative_ordering, relative_ordering,
} }
@@ -108,8 +100,8 @@ pub fn compute_with_check_from_reference<'a>(
reference: &'a BenchmarkResult, reference: &'a BenchmarkResult,
sort_order: SortOrder, sort_order: SortOrder,
) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'a>>> { ) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'a>>> {
if fastest_of(results).mean_wall_clock_time().get::<second>() == 0.0 if fastest_of(results).mean_wall_clock_time() == Time::zero()
|| reference.mean_wall_clock_time().get::<second>() == 0.0 || reference.mean_wall_clock_time() == Time::zero()
{ {
return None; return None;
} }
@@ -123,7 +115,7 @@ pub fn compute_with_check(
) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'_>>> { ) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'_>>> {
let fastest = fastest_of(results); let fastest = fastest_of(results);
if fastest.mean_wall_clock_time().get::<second>() == 0.0 { if fastest.mean_wall_clock_time() == Time::zero() {
return None; return None;
} }
-8
View File
@@ -82,17 +82,9 @@ pub fn execute_and_measure(mut command: Command) -> Result<Measurement> {
discard(output); discard(output);
} }
#[cfg(not(windows))]
let (time_user, time_system, peak_memory_usage, exit_status) = cpu_timer.stop(child)?; let (time_user, time_system, peak_memory_usage, exit_status) = cpu_timer.stop(child)?;
#[cfg(windows)]
let exit_status = child.wait()?;
let time_wall_clock = wallclock_timer.stop(); let time_wall_clock = wallclock_timer.stop();
#[cfg(windows)]
let (time_user, time_system, peak_memory_usage) = cpu_timer.stop();
Ok(Measurement { Ok(Measurement {
time_wall_clock, time_wall_clock,
time_user, time_user,
+13 -10
View File
@@ -1,7 +1,10 @@
#![cfg(windows)] #![cfg(windows)]
#![warn(unsafe_op_in_unsafe_fn)] #![warn(unsafe_op_in_unsafe_fn)]
use std::{mem, os::windows::io::AsRawHandle, process, ptr}; use std::process::{self, Child, ExitStatus};
use std::{mem, os::windows::io::AsRawHandle, ptr};
use anyhow::Result;
use windows_sys::Win32::{ use windows_sys::Win32::{
Foundation::{CloseHandle, HANDLE}, Foundation::{CloseHandle, HANDLE},
@@ -31,11 +34,11 @@ use crate::quantity::{nanosecond, Information, Time, Zero};
#[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)]
static NtResumeProcess: Lazy<unsafe extern "system" fn(ProcessHandle: HANDLE) -> NTSTATUS> = static NtResumeProcess: Lazy<unsafe extern "system" fn(process_handle: HANDLE) -> NTSTATUS> =
Lazy::new(|| { Lazy::new(|| {
// SAFETY: Getting the module handle for ntdll.dll is safe // SAFETY: Getting the module handle for ntdll.dll is safe
let ntdll = unsafe { GetModuleHandleW(w!("ntdll.dll")) }; let ntdll = unsafe { GetModuleHandleW(w!("ntdll.dll")) };
assert!(ntdll != std::ptr::null_mut(), "GetModuleHandleW failed"); assert!(!ntdll.is_null(), "GetModuleHandleW failed");
// SAFETY: The ntdll handle is valid // SAFETY: The ntdll handle is valid
let nt_resume_process = unsafe { GetProcAddress(ntdll, s!("NtResumeProcess")) }; let nt_resume_process = unsafe { GetProcAddress(ntdll, s!("NtResumeProcess")) };
@@ -54,10 +57,7 @@ impl CPUTimer {
// SAFETY: Creating a new job object is safe // SAFETY: Creating a new job object is safe
let job_object = unsafe { CreateJobObjectW(ptr::null_mut(), ptr::null_mut()) }; let job_object = unsafe { CreateJobObjectW(ptr::null_mut(), ptr::null_mut()) };
assert!( assert!(!job_object.is_null(), "CreateJobObjectW failed");
job_object != std::ptr::null_mut(),
"CreateJobObjectW failed"
);
// SAFETY: The job object handle is valid // SAFETY: The job object handle is valid
let ret = unsafe { AssignProcessToJobObject(job_object, child_handle) }; let ret = unsafe { AssignProcessToJobObject(job_object, child_handle) };
@@ -84,7 +84,9 @@ impl CPUTimer {
Self { job_object } Self { job_object }
} }
pub fn stop(&self) -> (Time, Time, Information) { pub fn stop(&self, mut child: Child) -> Result<(Time, Time, Information, ExitStatus)> {
let status = child.wait()?;
let mut job_object_info = let mut job_object_info =
mem::MaybeUninit::<JOBOBJECT_BASIC_ACCOUNTING_INFORMATION>::uninit(); mem::MaybeUninit::<JOBOBJECT_BASIC_ACCOUNTING_INFORMATION>::uninit();
@@ -113,9 +115,10 @@ impl CPUTimer {
// 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 system_time =
Time::new::<nanosecond>((job_object_info.TotalKernelTime as f64) * 100.0); Time::new::<nanosecond>((job_object_info.TotalKernelTime as f64) * 100.0);
(user_time, system_time, Information::zero())
Ok((user_time, system_time, Information::zero(), status))
} else { } else {
(Time::zero(), Time::zero(), Information::zero()) Ok((Time::zero(), Time::zero(), Information::zero(), status))
} }
} }
} }