CoreMark 1.01 ported to WebAssembly.
CoreMark is a simple, yet sophisticated benchmark that is designed specifically to test the functionality of a processor core. Running CoreMark produces a single-number score allowing users to make quick comparisons between processors.
Source: https://github.com/eembc/coremark
Online demo: here
- coremark.wasm - WASI app
- coremark-minimal.wasm - Simple wasm module with minimal runtime dependencies
- coremark-emcc.* - Emscripten build
Use any WASI-compatible runtime to run it directly:
# Wasm3
wasm3 coremark.wasm
# kanaka/wac
wax coremark.wasm
# wasmtime
wasmtime coremark.wasm
# WAVM
wavm run coremark.wasm
# Wasmer
wasmer run --singlepass coremark.wasm
wasmer run --cranelift coremark.wasm
wasmer run --llvm coremark.wasm
# Wasmer-JS (V8)
wasmer-js run coremark.wasm
# Wasmer-JS (V8 interpreter)
node --wasm-interpret-all $(which wasmer-js) run coremark.wasmWith no arguments the benchmark picks its own iteration count, aiming for a run of 10 seconds or more. All four CoreMark parameters can be given instead:
# seed1 seed2 seed3 iterations
wasm3 coremark.wasm 0x0 0x0 0x66 60000 # performance run
wasm3 coremark.wasm 0x3415 0x3415 0x66 60000 # validation runPass 0 as the iteration count to keep the automatic calibration. A run of
under 10 seconds reports a score, but is not a valid CoreMark result.
You can open it with your browser.
Run a local copy:
python3 -m http.server 8000
# visit http://localhost:8000/coremark-emcc.htmlUsing Node.js:
node coremark-emcc.jsYou can open it with your browser.
Here are some examples of how to load and execute it using different engines:
coremark-minimal.html- JavaScript example using your browser's engine.coremark-minimal.mjs- Node.js example using V8.coremark-minimal.py- Python 3 example usingWasm3engine.wasmi-coremark- Rust example usingWasmtime,Wasm3,wasmi.
Both local examples expect coremark-minimal.wasm next to them:
# Node.js
node coremark-minimal.mjs
# Python 3, via the wasm3 bindings
pip install pywasm3
./coremark-minimal.pyServe the directory to run the browser example:
python3 -m http.server 8000
# visit http://localhost:8000/coremark-minimal.htmlTo run with any wasm runtime:
- You need to provide an
u64 env.clock_ms()function, which should return current time in milliseconds. - Call
f32 run()function. It should take12..20seconds to execute and return a CoreMark result.
Wasm3 supplies clock_ms itself, so its CLI can run the module directly:
wasm3 --func run coremark-minimal.wasmbuild.sh clones the CoreMark sources at a pinned revision,
builds each target in its own scratch copy under build/, and drops the result
in the repository root:
export WASI_SDK=/path/to/wasi-sdk-34.0-x86_64-linux
./build.sh # coremark.wasm and coremark-minimal.wasm
./build.sh emcc # coremark-emcc.{html,js,wasm}, needs emcc on PATH
./build.sh native # coremark.elf, for comparison against the hostThree ports live in ports/:
ports/wasibuilds on CoreMark'sposixport.ports/emccis the sameposixport, for the Emscripten build.ports/minimalis a bare-module port derived from CoreMark'sbarebonesone: no WASI, no libc I/O, no command line. It takes the clock from anenv.clock_msimport and exportsrun.
All three wasm builds enable the Lime1 feature set, plus tail calls:
mutable-globals bulk-memory-opt
multivalue extended-const
sign-ext call-indirect-overlong
nontrapping-fptoint tail-call
An engine has to implement all of them to load the modules. Drop
WASM_FEATURES in build.sh to a smaller set to target an older
one; LLVM spells the Lime1 half of the list as -mcpu=lime1.
.github/workflows/build.yml builds every push
and pull request and uploads the binaries as a run artifact. Pushing a v* tag
publishes them as a GitHub release:
git tag v1.0.0
git push origin v1.0.0The same workflow deploys the demo pages from main to GitHub Pages.
The toolchains are pinned in the workflow (WASI_SDK_VERSION, EMSCRIPTEN_VERSION),
and each build records the exact versions in toolchain.txt next to the
binaries:
# WASI
wasi-sdk 34.0
clang version 23.1.0-wasi-sdk
# EMCC
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 6.0.8
clang version 24.0.0git