From f02f9ec4f184c0b6f9856c6107952596ca3b9aef Mon Sep 17 00:00:00 2001 From: "Jiaxiao (mossaka) Zhou" Date: Fri, 6 Dec 2024 18:13:49 +0000 Subject: [PATCH] benches: refactor to extract the image base name out Signed-off-by: Jiaxiao (mossaka) Zhou --- .../benches/wasi-demo-app-benchmarks.rs | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/benches/containerd-shim-benchmarks/benches/wasi-demo-app-benchmarks.rs b/benches/containerd-shim-benchmarks/benches/wasi-demo-app-benchmarks.rs index 8227c2253..c59fb7c44 100644 --- a/benches/containerd-shim-benchmarks/benches/wasi-demo-app-benchmarks.rs +++ b/benches/containerd-shim-benchmarks/benches/wasi-demo-app-benchmarks.rs @@ -3,21 +3,10 @@ use std::time::{Duration, Instant}; use criterion::{criterion_group, criterion_main, Criterion}; -fn run_container(runtime: &str, oci: bool) -> Duration { - let start = Instant::now(); - - let image_name = if oci { - "ghcr.io/containerd/runwasi/wasi-demo-oci:latest" // OCI artifact - } else { - "ghcr.io/containerd/runwasi/wasi-demo-app:latest" - }; +static RUNTIMES: &[&str] = &["wasmtime", "wasmedge", "wasmer", "wamr"]; - let container_name = "testwasm"; - let wasm_file = if oci { - "wasi-demo-oci.wasm" - } else { - "wasi-demo-app.wasm" - }; +fn run_container(runtime: &str, image_base_name: &str) -> Duration { + let start = Instant::now(); let output = Command::new("sudo") .args([ @@ -25,9 +14,9 @@ fn run_container(runtime: &str, oci: bool) -> Duration { "run", "--rm", &format!("--runtime=io.containerd.{}.v1", runtime), - image_name, - container_name, - wasm_file, + &format!("ghcr.io/containerd/runwasi/{}:latest", image_base_name), + "testwasm", + &format!("{}.wasm", image_base_name), "echo", "hello", ]) @@ -50,17 +39,15 @@ fn run_container(runtime: &str, oci: bool) -> Duration { fn benchmark_startup(c: &mut Criterion) { let mut group = c.benchmark_group("wasi-demo-app"); - const RUNTIMES: &[&str] = &["wasmtime", "wasmedge", "wasmer", "wamr"]; - for runtime in RUNTIMES { - group.bench_function(runtime, |b| { - b.iter(|| run_container(runtime, false)); + group.bench_function(*runtime, |b| { + b.iter(|| run_container(runtime, "wasi-demo-app")); }); } for runtime in RUNTIMES { let name = format!("{}-oci", runtime); group.bench_function(&name, |b| { - b.iter(|| run_container(runtime, true)); + b.iter(|| run_container(runtime, "wasi-demo-oci")); }); }