Skip to content

Commit de5b992

Browse files
authored
Merge pull request #1468 from rust-lang/runtime-cli-iterations
Allow specifying the number of executed iterations for runtime benchmarks
2 parents 818f56f + 8029302 commit de5b992

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

collector/src/bin/collector.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ enum Commands {
575575
/// Include only benchmarks matching a prefix in this comma-separated list
576576
#[clap(long)]
577577
include: Option<String>,
578+
579+
/// How many iterations of each benchmark should be executed.
580+
#[clap(long, default_value = "5")]
581+
iterations: u32,
578582
},
579583
/// Benchmarks a local rustc
580584
BenchLocal {
@@ -706,12 +710,14 @@ fn main_result() -> anyhow::Result<i32> {
706710
id,
707711
exclude,
708712
include,
713+
iterations,
709714
} => {
710715
bench_runtime(
711716
&rustc,
712717
id.as_deref(),
713718
BenchmarkFilter::new(exclude, include),
714719
runtime_benchmark_dir,
720+
iterations,
715721
)?;
716722
Ok(0)
717723
}

collector/src/runtime/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub fn bench_runtime(
1818
id: Option<&str>,
1919
filter: BenchmarkFilter,
2020
benchmark_dir: PathBuf,
21+
iterations: u32,
2122
) -> anyhow::Result<()> {
2223
let toolchain = get_local_toolchain(&[Profile::Opt], rustc, None, None, id, "")?;
2324
let suite = benchmark::discover_benchmarks(&toolchain, &benchmark_dir)?;
@@ -32,7 +33,7 @@ pub fn bench_runtime(
3233

3334
let mut benchmark_index = 0;
3435
for binary in suite.groups {
35-
for message in execute_runtime_benchmark_binary(&binary.binary, &filter)? {
36+
for message in execute_runtime_benchmark_binary(&binary.binary, &filter, iterations)? {
3637
let message = message.map_err(|err| {
3738
anyhow::anyhow!(
3839
"Cannot parse BenchmarkMessage from benchmark {}: {err:?}",
@@ -64,13 +65,16 @@ pub fn bench_runtime(
6465
fn execute_runtime_benchmark_binary(
6566
binary: &Path,
6667
filter: &BenchmarkFilter,
68+
iterations: u32,
6769
) -> anyhow::Result<impl Iterator<Item = anyhow::Result<BenchmarkMessage>>> {
6870
// Turn off ASLR
6971
let mut command = Command::new("setarch");
7072
command.arg(std::env::consts::ARCH);
7173
command.arg("-R");
7274
command.arg(binary);
7375
command.arg("run");
76+
command.arg("--iterations");
77+
command.arg(&iterations.to_string());
7478

7579
if let Some(ref exclude) = filter.exclude {
7680
command.args(&["--exclude", exclude]);

0 commit comments

Comments
 (0)