Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraks committed Oct 2, 2024
1 parent a5be6f4 commit 089c6c2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
18 changes: 18 additions & 0 deletions benchmarks/wasm/even_odd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[no_mangle]
#[inline(never)]
fn is_even(n: u32) -> bool {
if n == 0 { true }
else { is_odd(n - 1) }
}

#[no_mangle]
#[inline(never)]
fn is_odd(n: u32) -> bool {
if n == 0 { false }
else { is_even(n - 1) }
}

#[no_mangle]
fn real_main() -> bool {
is_even(12)
}
35 changes: 35 additions & 0 deletions benchmarks/wasm/even_odd.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(module
(type (;0;) (func (param i32) (result i32)))
(type (;1;) (func (result i32)))
(func (;0;) (type 0) (param i32) (result i32)
block ;; label = @1
local.get 0
br_if 0 (;@1;)
i32.const 1
return
end
local.get 0
i32.const -1
i32.add
call 1)
(func (;1;) (type 0) (param i32) (result i32)
block ;; label = @1
local.get 0
br_if 0 (;@1;)
i32.const 0
return
end
local.get 0
i32.const -1
i32.add
call 0)
(func (;2;) (type 1) (result i32)
i32.const 0
call 1)
(start 2)
(table (;0;) 1 1 funcref)
(memory (;0;) 16)
(export "memory" (memory 0))
(export "is_even" (func 0))
(export "is_odd" (func 1))
(export "real_main" (func 2)))

0 comments on commit 089c6c2

Please sign in to comment.