This is a simulation of the wave equation ∂2u/∂t2 = c2(∂2u/∂x2+∂2u/∂y2) across a 2D manifold with a boundary condition of u=0 along the unit circle. Use the mouse to create waves.
It contains 5 implementations of the same code:
- C code compiled by Clang/Binaryen (WebAssembly Studio)
- C code compiled by Enscripten
- JS-like code compiled by Walt to WebAssembly
- TypeScript-like code compiled by AssemblyScript to WebAssembly
This particular algorithm processes large arrays but does no floating point calculations. Memory is visible to bot JS and WebAssembly and almost all CPU time is spent in the algorithm itself. (The canvas API introduces a minor overhead of about 10%.)
There are two options for generating the .wasm file:
- C: In directory
emcc emscripten.c -Os -s WASM=1 -s SIDE_MODULE=1 -o emscripten.wasm
- Walt: In directory
npm run buildto compile
- AssemblyScript: In directory
npm run asbuildto compile
index.tsto wasm files.
test.html loads the JS and .wasm modules, tests them on a 5x5 grid, and and displays the results.
online_versionshas copies of older versions on online IDEs.
webassembly_studiohas a version comparing JS and C, available at WebAssembly Studio
codepenhas an older version with .wasm bundled inline as a base64 string. (Codepen isn't as useful for benchmarking since it mangles JS but not WebAssembly.)
This project is licensed under the MIT License.