Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

bench: wait for the app when reading its output fails; say what --runs costs

Milosz54523f8eeb8e
diff --git a/README.md b/README.md
index a5dcb3c..8c3b885 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ Or step by step:
| `port [id]` | records up to 500 real calls, creates a one-function Rust crate + `TASK.md` |
| `verify` | release-builds the port and replays every recorded call |
| `enable` / `disable` | swaps the Rust in or out (one marked block, removed byte for byte) |
-| `bench` | times the whole app in rotated rounds of original, original again (an A/A control for noise) and Rust; wall and CPU time |
+| `bench` | times the whole app in rotated rounds of original, original again (an A/A control for noise) and Rust, plus one warm-up per side (`--runs 5` = 11 original runs, 6 Rust runs); wall and CPU time |
| `report` | markdown + SVG card for your PR |
| `doctor` | checks Rust, your runtimes and your agents |
diff --git a/src/bench.rs b/src/bench.rs
index a690ecd..3b1964b 100644
--- a/src/bench.rs
+++ b/src/bench.rs
@@ -212,8 +212,14 @@ fn output_with_cpu(cmd: &mut Command) -> std::io::Result<(Output, Option<f64>)>
buf
});
let mut out = Vec::new();
- if let Some(mut o) = stdout {
- o.read_to_end(&mut out)?;
+ if let Some(mut o) = stdout
+ && let Err(e) = o.read_to_end(&mut out)
+ {
+ // don't leave the child running or unwaited for
+ let _ = child.kill();
+ let _ = child.wait();
+ let _ = errors.join();
+ return Err(e);
}
let err = errors.join().unwrap_or_default();
let status = child.wait()?;
@@ -280,6 +286,8 @@ mod cpu {
}
/// A job object per run: it adds up the CPU time of every process in it, children included.
+ /// The child joins it just after spawn, so a process it starts before that isn't counted;
+ /// spawning with CREATE_SUSPENDED and resuming its main thread after joining would close that gap.
pub struct Meter {
job: Handle,
attached: bool,
diff --git a/src/main.rs b/src/main.rs
index 448b80b..dbe6360 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -55,7 +55,7 @@ enum Cmd {
/// Agent attempts per function before giving up
#[arg(long, default_value_t = 3)]
attempts: usize,
- /// Benchmark rounds (each runs the original twice and Rust once)
+ /// Benchmark rounds: each runs the original twice and Rust once, plus one warm-up per side (5 = 11 original runs, 6 Rust runs)
#[arg(long, default_value_t = 5)]
runs: usize,
/// Real calls to record per function
@@ -116,7 +116,7 @@ enum Cmd {
},
/// Time your app with the originals vs the Rust ports
Bench {
- /// Rounds: each runs the original twice (an A/A control for noise) and Rust once
+ /// Rounds: each runs the original twice (an A/A control for noise) and Rust once, plus one warm-up per side (5 = 11 original runs, 6 Rust runs)
#[arg(long, default_value_t = 5)]
runs: usize,
},