Skip to content

Commit

Permalink
benches: refactor to extract the image base name out
Browse files Browse the repository at this point in the history
Signed-off-by: Jiaxiao (mossaka) Zhou <[email protected]>
  • Loading branch information
Mossaka committed Dec 6, 2024
1 parent 8061d57 commit f02f9ec
Showing 1 changed file with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@ 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([
"ctr",
"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",
])
Expand All @@ -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"));
});
}

Expand Down

0 comments on commit f02f9ec

Please sign in to comment.