summaryrefslogtreecommitdiff
path: root/benchmarks/benches/fibonacci.rs
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2024-05-10 18:08:00 +0200
committerHenry Gressmann <mail@henrygressmann.de>2024-05-10 19:22:29 +0200
commit868aa006b7f1eabffd4aec3a03555012148a7df1 (patch)
tree164722ac37b3efb0f40bcf53925b7e79dc6493c1 /benchmarks/benches/fibonacci.rs
parent2ac04cd653898786caca198726e6b9938185b76a (diff)
chore: slight perf improvements
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'benchmarks/benches/fibonacci.rs')
-rw-r--r--benchmarks/benches/fibonacci.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/benchmarks/benches/fibonacci.rs b/benchmarks/benches/fibonacci.rs
index b391285..15c09ac 100644
--- a/benchmarks/benches/fibonacci.rs
+++ b/benchmarks/benches/fibonacci.rs
@@ -1,9 +1,8 @@
mod util;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
-use util::wasm_to_twasm;
-fn run_tinywasm(twasm: &[u8], iterations: i32, name: &str) {
- let (mut store, instance) = util::tinywasm(twasm);
+fn run_tinywasm(wasm: &[u8], iterations: i32, name: &str) {
+ let (mut store, instance) = util::tinywasm(wasm);
let fib = instance.exported_func::<i32, i32>(&store, name).expect("exported_func");
fib.call(&mut store, iterations).expect("call");
}
@@ -47,12 +46,10 @@ fn run_native_recursive(n: i32) -> i32 {
const FIBONACCI: &[u8] = include_bytes!("../../examples/rust/out/fibonacci.wasm");
fn criterion_benchmark(c: &mut Criterion) {
- let twasm = wasm_to_twasm(FIBONACCI);
-
{
let mut group = c.benchmark_group("fibonacci");
group.bench_function("native", |b| b.iter(|| run_native(black_box(60))));
- group.bench_function("tinywasm", |b| b.iter(|| run_tinywasm(&twasm, black_box(60), "fibonacci")));
+ group.bench_function("tinywasm", |b| b.iter(|| run_tinywasm(FIBONACCI, black_box(60), "fibonacci")));
group.bench_function("wasmi", |b| b.iter(|| run_wasmi(FIBONACCI, black_box(60), "fibonacci")));
group.bench_function("wasmer", |b| b.iter(|| run_wasmer(FIBONACCI, black_box(60), "fibonacci")));
}
@@ -61,7 +58,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("fibonacci-recursive");
group.measurement_time(std::time::Duration::from_secs(5));
group.bench_function("native", |b| b.iter(|| run_native_recursive(black_box(26))));
- group.bench_function("tinywasm", |b| b.iter(|| run_tinywasm(&twasm, black_box(26), "fibonacci_recursive")));
+ group.bench_function("tinywasm", |b| b.iter(|| run_tinywasm(FIBONACCI, black_box(26), "fibonacci_recursive")));
group.bench_function("wasmi", |b| b.iter(|| run_wasmi(FIBONACCI, black_box(26), "fibonacci_recursive")));
group.bench_function("wasmer", |b| b.iter(|| run_wasmer(FIBONACCI, black_box(26), "fibonacci_recursive")));
}