Skip to content

Commit e440cbe

Browse files
ci: add benchmark config
1 parent 405ef34 commit e440cbe

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

crates/bench_tools/src/main.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bench_tools::types::benchmark_config::{find_benchmarks_by_package, BENCHMARKS};
12
use clap::{Parser, Subcommand};
23

34
#[derive(Parser)]
@@ -18,14 +19,45 @@ enum Commands {
1819
#[arg(short, long)]
1920
out: String,
2021
},
22+
/// List benchmarks for a package.
23+
List {
24+
/// Package name to list benchmarks for. If not provided, lists all benchmarks.
25+
#[arg(short, long)]
26+
package: Option<String>,
27+
},
2128
}
2229

2330
fn main() {
2431
let cli = Cli::parse();
25-
2632
match cli.command {
2733
Commands::Run { package: _, out: _ } => {
2834
unimplemented!()
2935
}
36+
Commands::List { package } => match package {
37+
Some(package_name) => {
38+
let benchmarks = find_benchmarks_by_package(&package_name);
39+
40+
if benchmarks.is_empty() {
41+
println!("No benchmarks found for package: {}", package_name);
42+
return;
43+
}
44+
45+
println!("Available benchmarks for package '{}':", package_name);
46+
for bench in &benchmarks {
47+
println!(" - {} (runs: {})", bench.name, bench.cmd_args.join(" "));
48+
}
49+
}
50+
None => {
51+
println!("All available benchmarks:");
52+
for bench in BENCHMARKS {
53+
println!(
54+
" - {} (package: {}, runs: {})",
55+
bench.name,
56+
bench.package,
57+
bench.cmd_args.join(" ")
58+
);
59+
}
60+
}
61+
},
3062
}
3163
}

crates/bench_tools/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod benchmark_config;
12
pub mod estimates;
23
#[cfg(test)]
34
mod estimates_test;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/// Configuration for a single benchmark.
2+
#[derive(Debug, Clone)]
3+
pub struct BenchmarkConfig {
4+
pub name: &'static str,
5+
pub package: &'static str,
6+
pub cmd_args: &'static [&'static str],
7+
}
8+
9+
impl BenchmarkConfig {
10+
/// Get the full cargo bench command as owned strings.
11+
pub fn cmd_args_owned(&self) -> Vec<String> {
12+
self.cmd_args.iter().map(|s| s.to_string()).collect()
13+
}
14+
}
15+
16+
/// All available benchmarks defined as a const array.
17+
pub const BENCHMARKS: &[BenchmarkConfig] = &[
18+
BenchmarkConfig {
19+
name: "full_committer_flow",
20+
package: "starknet_committer_and_os_cli",
21+
cmd_args: &["bench", "-p", "starknet_committer_and_os_cli", "full_committer_flow"],
22+
},
23+
BenchmarkConfig {
24+
name: "single_tree_flow",
25+
package: "starknet_committer_and_os_cli",
26+
cmd_args: &["bench", "-p", "starknet_committer_and_os_cli", "single_tree_flow"],
27+
},
28+
BenchmarkConfig {
29+
name: "gateway_apply_block",
30+
package: "apollo_gateway",
31+
cmd_args: &["bench", "-p", "apollo_gateway", "apply_block"],
32+
},
33+
];
34+
35+
/// Helper functions for working with benchmarks.
36+
pub fn find_benchmark_by_name(name: &str) -> Option<&'static BenchmarkConfig> {
37+
BENCHMARKS.iter().find(|b| b.name == name)
38+
}
39+
40+
pub fn find_benchmarks_by_package(package: &str) -> Vec<&'static BenchmarkConfig> {
41+
BENCHMARKS.iter().filter(|b| b.package == package).collect()
42+
}

0 commit comments

Comments
 (0)