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 build script for Rust based Wasm benchmarks #1111

Merged
merged 6 commits into from
Jul 6, 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
204 changes: 204 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"crates/wasmi/benches/rust/tiny_keccak",
"crates/wasmi/benches/rust/reverse_complement",
"crates/wasmi/benches/rust/regex_redux",
"crates/wasmi/benches/rust/build",
"fuzz",
]
exclude = []
Expand Down
18 changes: 18 additions & 0 deletions crates/wasmi/benches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Rust based Benchmarks

## Building

Build with

```
cargo run --package build_benches
```

This builds the benchmark `.wasm` files for all the Rust based benchmarks
such as `tiny_keccak`, `reverse_complement` and `regex_redux` with proper
optimizations and stores the results in their respective directories.

## Usage

Use this script whenever a benchmark has changed or when a new Rust, LLVM or `wasm-opt`
version has been released.
1 change: 1 addition & 0 deletions crates/wasmi/benches/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use wasmi::{Config, StackLimits};
/// # Panics
///
/// If the benchmark Wasm file could not be opened, read or parsed.
#[track_caller]
pub fn load_wasm_from_file(file_name: &str) -> Vec<u8> {
let mut file = File::open(file_name)
.unwrap_or_else(|error| panic!("could not open benchmark file {}: {}", file_name, error));
Expand Down
15 changes: 8 additions & 7 deletions crates/wasmi/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,19 @@ fn bench_translate_for_all(c: &mut Criterion, name: &str, path: &str) {
}

fn bench_translate_tiny_keccak(c: &mut Criterion) {
bench_translate_for_all(c, "tiny_keccak", "benches/rust/tiny_keccak.wasm");
bench_translate_for_all(c, "tiny_keccak", "benches/rust/tiny_keccak/out.wasm");
}

fn bench_translate_reverse_complement(c: &mut Criterion) {
bench_translate_for_all(
c,
"reverse_complement",
"benches/rust/reverse_complement.wasm",
"benches/rust/reverse_complement/out.wasm",
);
}

fn bench_translate_regex_redux(c: &mut Criterion) {
bench_translate_for_all(c, "regex_redux", "benches/rust/regex_redux.wasm");
bench_translate_for_all(c, "regex_redux", "benches/rust/regex_redux/out.wasm");
}

fn bench_translate_spidermonkey(c: &mut Criterion) {
Expand Down Expand Up @@ -427,7 +427,7 @@ fn bench_translate_case_worst_stackbomb_big(c: &mut Criterion) {
fn bench_instantiate_using(c: &mut Criterion, name: &str) {
let id = format!("instantiate/{name}");
c.bench_function(&id, |b| {
let path = format!("benches/rust/{name}.wasm");
let path = format!("benches/rust/{name}/out.wasm");
let module = load_module_from_file(&path);
let linker = <Linker<()>>::new(module.engine());
b.iter(|| {
Expand Down Expand Up @@ -724,7 +724,7 @@ fn bench_instantiate_erc1155(c: &mut Criterion) {

fn bench_execute_tiny_keccak(c: &mut Criterion) {
c.bench_function("execute/tiny_keccak", |b| {
let (mut store, instance) = load_instance_from_file("benches/rust/tiny_keccak.wasm");
let (mut store, instance) = load_instance_from_file("benches/rust/tiny_keccak/out.wasm");
let data_ptr = instance
.get_typed_func::<(), i32>(&store, "setup")
.unwrap()
Expand All @@ -744,7 +744,8 @@ fn bench_execute_tiny_keccak(c: &mut Criterion) {

fn bench_execute_rev_comp(c: &mut Criterion) {
c.bench_function("execute/reverse_complement", |b| {
let (mut store, instance) = load_instance_from_file("benches/rust/reverse_complement.wasm");
let (mut store, instance) =
load_instance_from_file("benches/rust/reverse_complement/out.wasm");

// Allocate buffers for the input and output.
let data_ptr = instance
Expand Down Expand Up @@ -796,7 +797,7 @@ fn bench_execute_rev_comp(c: &mut Criterion) {

fn bench_execute_regex_redux(c: &mut Criterion) {
c.bench_function("execute/regex_redux", |b| {
let (mut store, instance) = load_instance_from_file("benches/rust/regex_redux.wasm");
let (mut store, instance) = load_instance_from_file("benches/rust/regex_redux/out.wasm");

// Allocate buffers for the input and output.
let data_ptr = instance
Expand Down
Loading
Loading