Skip to content

Commit

Permalink
FIXES bytecodealliance#137: make calling wasm from python 7x faster
Browse files Browse the repository at this point in the history
  • Loading branch information
muayyad-alsadi committed Apr 5, 2023
1 parent 8417fba commit 5bb5c39
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion examples/gcd_perf.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import wasmtime.loader
import time
from math import gcd as math_gcd
from gcd import gcd_func as wasm_gcd


def python_gcd(x, y):
while y:
x, y = y, x % y
return abs(x)


a = 16516842
b = 154654684

print(math_gcd(a, b), python_gcd(a, b), wasm_gcd(a, b))

N = 1_000
by_name = locals()
for name in "math_gcd", "python_gcd", "wasm_gcd":
Expand Down
4 changes: 3 additions & 1 deletion examples/simd_i8x16.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

instance = Instance(store, module, [])
vector_type = ctypes.c_uint8 * 16
add_v128_f: Func = instance.exports(store)["add_v128"]
add_v128_f = instance.exports(store)["add_v128"]
if not isinstance(add_v128_f, Func):
raise TypeError("expecting Func")
add_v128 = partial(add_v128_f, store)
a = vector_type(*(i for i in range(16)))
b = vector_type(*(40 + i for i in range(16)))
Expand Down
4 changes: 3 additions & 1 deletion tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def test_simd_i8x16_add(self):

instance = Instance(store, module, [])
vector_type = ctypes.c_uint8 * 16
add_v128_f: Func = instance.exports(store)["add_v128"]
add_v128_f = instance.exports(store)["add_v128"]
if not isinstance(add_v128_f, Func):
raise TypeError("expecting Func")
add_v128 = partial(add_v128_f, store)
a = vector_type(*(i for i in range(16)))
b = vector_type(*(40 + i for i in range(16)))
Expand Down

0 comments on commit 5bb5c39

Please sign in to comment.