Skip to content

Commit f42dfc9

Browse files
committed
Initial commit
1 parent c6535a4 commit f42dfc9

8 files changed

+54
-1
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ coremark
2020
2. Call `f32 run()` function. It should take `12..20` seconds to execute and return a CoreMark result.
2121

2222
`coremark-minimal.py` is provided as an example of how to load and execute it with Wasm3 engine using `pywasm3`.
23-
You can also use `coremark-minimal.html` to load it in your browser.
23+
24+
You can also use `coremark-minimal.html` to load it in your browser:
25+
```sh
26+
python3 -m http.server 8000
27+
# visit http://localhost:8000/coremark-minimal.html
28+
```
2429

2530
## Build instructions
2631

coremark-emcc.html

+1
Large diffs are not rendered by default.

coremark-emcc.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coremark-emcc.wasm

18.4 KB
Binary file not shown.

coremark-minimal.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<html>
2+
<body>
3+
<script>
4+
fetch('coremark-minimal.wasm').then(response =>
5+
response.arrayBuffer()
6+
).then(bytes =>
7+
WebAssembly.instantiate(bytes, { env: {
8+
clock_ms: () => Date.now()
9+
}})
10+
).then((r) => {
11+
let result = r.instance.exports.run()
12+
alert(result.toFixed(3))
13+
});
14+
</script>
15+
</body>
16+
</html>

coremark-minimal.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
import os, time
4+
import wasm3
5+
6+
scriptpath = os.path.dirname(os.path.realpath(__file__))
7+
wasm_fn = os.path.join(scriptpath, "./coremark-minimal.wasm")
8+
9+
print("Initializing Wasm3 engine...")
10+
11+
def clock_ms():
12+
return int(round(time.time() * 1000))
13+
14+
env = wasm3.Environment()
15+
rt = env.new_runtime(2048)
16+
17+
with open(wasm_fn, "rb") as f:
18+
mod = env.parse_module(f.read())
19+
rt.load(mod)
20+
mod.link_function("env", "clock_ms", "i()", clock_ms)
21+
22+
wasm_run = rt.find_function("run")
23+
24+
print("Running CoreMark 1.0...")
25+
res = wasm_run()
26+
27+
if res > 1:
28+
print(f"Result: {res:.3f}")
29+
else:
30+
print("Error")

coremark-minimal.wasm

7.71 KB
Binary file not shown.

coremark.wasm

33.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)