Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Merge main into M4.6; mixer perf test measures thread CPU time (wall clock failed under machine load)

Brandon Thomas2ad851389864
diff --git a/crates/render/Cargo.toml b/crates/render/Cargo.toml
index 315bd48c4..e9d35f49f 100644
--- a/crates/render/Cargo.toml
+++ b/crates/render/Cargo.toml
@@ -25,3 +25,7 @@ serde_json = { workspace = true }
[dev-dependencies]
image = { version = "0.25", default-features = false, features = ["png"] }
+
+# Thread CPU clock for load-robust performance tests.
+[target.'cfg(unix)'.dev-dependencies]
+rustix = { version = "1", default-features = false, features = ["std", "time"] }
diff --git a/crates/render/src/mixer_tests.rs b/crates/render/src/mixer_tests.rs
index 154b98298..c6c44b251 100644
--- a/crates/render/src/mixer_tests.rs
+++ b/crates/render/src/mixer_tests.rs
@@ -424,15 +424,34 @@ fn perf_24_tracks_3_effects_realtime_factor() {
let pool = rayon::ThreadPoolBuilder::new().num_threads(1).build().unwrap();
// warm up (fresh graph + pre-roll), then time steady-state playback-sized blocks
pool.install(|| r.mix_cut(0, 4_800, &[1024], None));
- let t0 = std::time::Instant::now();
- pool.install(|| r.mix_cut(4_800, n, &[1024], None));
- let el = t0.elapsed().as_secs_f64();
+ // Thread CPU time, not wall clock: the test runs alongside the whole suite (and other builds),
+ // and only the work done on this one thread matters.
+ let el = pool.install(|| {
+ let t0 = thread_cpu_secs();
+ let w0 = std::time::Instant::now();
+ r.mix_cut(4_800, n, &[1024], None);
+ t0.map(|t0| thread_cpu_secs().unwrap_or(t0) - t0).unwrap_or_else(|| w0.elapsed().as_secs_f64())
+ });
let rt = secs / el;
- eprintln!("mixer perf: 24 tracks x 3 inserts + submix, {secs} s of 48 kHz stereo in {el:.3} s on one core = {rt:.1}x realtime");
+ eprintln!("mixer perf: 24 tracks x 3 inserts + submix, {secs} s of 48 kHz stereo in {el:.3} s of CPU on one core = {rt:.1}x realtime");
let min = if cfg!(debug_assertions) { 1.0 } else { 4.0 };
assert!(rt > min, "realtime factor {rt:.2}");
}
+/// CPU seconds used by the calling thread (None where there is no thread clock; callers fall back
+/// to wall time).
+fn thread_cpu_secs() -> Option<f64> {
+ #[cfg(unix)]
+ {
+ let t = rustix::time::clock_gettime(rustix::time::ClockId::ThreadCPUTime);
+ Some(t.tv_sec as f64 + t.tv_nsec as f64 * 1e-9)
+ }
+ #[cfg(not(unix))]
+ {
+ None
+ }
+}
+
#[test]
fn audio_transition_curves() {
use crate::transitions::audio_gains;