forked from bytecodealliance/wasmtime-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIXES bytecodealliance#137: make calling wasm from python 7x faster
- Loading branch information
1 parent
dc3d697
commit 1446d79
Showing
3 changed files
with
77 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import wasmtime.loader | ||
import time | ||
from math import gcd as math_gcd | ||
from gcd import gcd_func as wasm_gcd | ||
from gcd_alt import gcd as wasm_gcd_alt | ||
|
||
def python_gcd(x, y): | ||
while y: | ||
x, y = y, x % y | ||
return abs(x) | ||
|
||
N = 1_000 | ||
by_name = locals() | ||
for name in 'math_gcd', 'python_gcd', 'wasm_gcd', 'wasm_gcd_alt': | ||
gcdf = by_name[name] | ||
start_time = time.perf_counter() | ||
for _ in range(N): | ||
g = gcdf(16516842, 154654684) | ||
total_time = time.perf_counter() - start_time | ||
print(total_time, "\t\t", name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters