Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add execution benchmarks #5185

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ wasmer = { version = "=5.0.0-rc.1", path = "lib/api", features = [
"sys",
] }
anyhow = "1.0"
criterion = { version = "0.5", default-features = false }
criterion = { version = "0.5", features = ["csv_output"] }
clap = { version = "=4.4.11" }
clap_builder = { version = "=4.4.11" }
clap_derive = { version = "=4.4.7" }
Expand Down Expand Up @@ -229,6 +229,10 @@ opt-level = 3
[profile.dev.package.digest]
opt-level = 3

[[bench]]
name = "compiler_run"
harness = false

[[bench]]
name = "deserialize_modules"
harness = false
Expand Down
77 changes: 77 additions & 0 deletions benches/compiler_run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use criterion::{criterion_group, criterion_main, Criterion};
use wasmer::*;

static BENCHMARKS_ARTIFACTS_BASE_URL: &str = "https://pub-53a226d993e144159d6f8b993fe0cbf3.r2.dev";

fn get_engine() -> Engine {
#[cfg(feature = "llvm")]
return LLVM::new().into();

#[cfg(feature = "singlepass")]
return Singlepass::new().into();

#[cfg(feature = "cranelift")]
return Cranelift::new().into();

#[cfg(not(any(feature = "cranelift", feature = "llvm", feature = "singlepass")))]
return Default::default();
}

pub fn run_fn(c: &mut Criterion, module: &[u8], name: &str, input: i64) {
c.bench_function(name, |b| {
let engine = get_engine();
let mut store = Store::new(engine);
let module = Module::new(&store, module).unwrap();
let import_object = imports! {};
let instance = Instance::new(&mut store, &module, &import_object).unwrap();
let func = instance
.exports
.get_typed_function::<i64, i64>(&store, "run")
.unwrap();

b.iter(|| {
func.call(&mut store, input);
})
});
}

pub fn download_and_run(c: &mut Criterion) {
let name = if cfg!(feature = "cranelift") {
"cranelift"
} else if cfg!(feature = "llvm") {
"llvm"
} else if cfg!(feature = "singlepass") {
"singlepass"
} else if cfg!(feature = "v8") {
"v8"
} else if cfg!(feature = "wamr") {
"wamr"
} else if cfg!(feature = "wasmi") {
"wasmi"
} else {
panic!("Unrecognized backend!")
};

let bytes = include_bytes!("./mods/counter.wasm");
run_fn(c, bytes, &format!("exec/{name}/counter"), 5_000_000);
let bytes = include_bytes!("./mods/primes.wasm");
run_fn(c, bytes, &format!("exec/{name}/primes"), 1_000);
let bytes = include_bytes!("./mods/fib_rec.wasm");
run_fn(c, bytes, &format!("exec/{name}/fib_rec"), 40);
let bytes = include_bytes!("./mods/fib_iter.wasm");
run_fn(c, bytes, &format!("exec/{name}/fib_iter"), 2_000_000);
let bytes = include_bytes!("./mods/bulk_ops.wasm");
run_fn(c, bytes, &format!("exec/{name}/bulk_ops"), 5_000);
let bytes = include_bytes!("./mods/matmul.wasm");
run_fn(c, bytes, &format!("exec/{name}/matmul"), 200);
let bytes = include_bytes!("./mods/argon2.wasm");
run_fn(c, bytes, &format!("exec/{name}/argon2"), 1);
}

criterion_group!(
name = run_benches;
config = Criterion::default().sample_size(60);
targets = download_and_run
);

criterion_main!(run_benches);
Binary file added benches/mods/argon2.wasm
Binary file not shown.
Binary file added benches/mods/bulk_ops.wasm
Binary file not shown.
Binary file added benches/mods/counter.wasm
Binary file not shown.
Binary file added benches/mods/fib_iter.wasm
Binary file not shown.
Binary file added benches/mods/fib_rec.wasm
Binary file not shown.
Binary file added benches/mods/matmul.wasm
Binary file not shown.
Binary file added benches/mods/primes.wasm
Binary file not shown.
Loading