-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.exs
63 lines (57 loc) · 1.33 KB
/
bench.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
mod1 = ~S/
(module
(func (export "add") (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add)
)
/
{:ok, pid1} = Wasmtime.load(%Wasmtime.FromBytes{bytes: mod1})
{:ok, [10]} = Wasmtime.call_func(pid1, "add", [3, 7])
mod2 = ~S/
(module
(func (export "plus_10") (param i32) (result i32)
local.get 0
i32.const 10
i32.add)
)
/
{:ok, pid2} = Wasmtime.load(%Wasmtime.FromBytes{bytes: mod2})
{:ok, [20]} = Wasmtime.call_func(pid2, "plus_10", [10])
mod3 = ~S/
(module
(import "" "" (func $compute (param i32) (result i32)))
(func (export "run") (param i32) (result i32) (call $compute (local.get 0)))
)
/
{:ok, pid3} =
Wasmtime.load(%Wasmtime.FromBytes{
bytes: mod3,
func_imports: [
{fn x ->
20 + x
end, [:i32], [:i32]}
]
})
{:ok, [200]} = Wasmtime.call_func(pid3, "run", [180])
Benchee.run(
%{
"add" => fn ->
Wasmtime.call_func(pid1, "add", [20, 40])
end,
"add_xt" => fn ->
Wasmtime.call_func_xt(pid1, "add", [20, 40])
end,
"plus_10" => fn ->
Wasmtime.call_func(pid2, "plus_10", [20])
end,
"plus_10_xt" => fn ->
Wasmtime.call_func_xt(pid2, "plus_10", [20])
end,
"imports" => fn ->
Wasmtime.call_func(pid3, "run", [10])
end
},
warmup: 20,
time: 60
)