Skip to content
JavaScript vs WebAssembly performance comparison - wave equation demo
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
as minor refactoring Jun 13, 2019
clang Renamed Emscripten version to Clang and introduced actual Emscripten … Feb 1, 2019
emscripten
js
online_versions/webassembly_studio
walt Added separate radio buttons for unoptimized and optimized AssemblySc… Apr 3, 2019
.gitignore Moved stuff around and checked in AssemblyScript build Dec 14, 2018
LICENSE Initial commit Aug 25, 2018
README.md Renamed Emscripten version to Clang and introduced actual Emscripten … Feb 1, 2019
index.css Updated index page and changed assemblyscript palette function Dec 15, 2018
index.html
test.css
test.html
test.js
wave.js Added separate radio buttons for unoptimized and optimized AssemblySc… Apr 3, 2019

README.md

webassembly-wave

Simple benchmark comparing performance of JavaScript vs. WebAssembly modules generated by different compilers.

LIVE DEMO

Description

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:

  • Standard JavaScript
  • 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%.)

Compiling program

There are two options for generating the .wasm file:

  • C: In directory emscripten compile emscripten.c with Emscripten: emcc emscripten.c -Os -s WASM=1 -s SIDE_MODULE=1 -o emscripten.wasm
  • Walt: In directory walt run npm install and npm run build to compile waves.walt to a waves.wasm file.
  • AssemblyScript: In directory as run npm install and npm run asbuild to compile index.ts to wasm files.

Other stuff

  • test.html loads the JS and .wasm modules, tests them on a 5x5 grid, and and displays the results.

  • Directory online_versions has copies of older versions on online IDEs.

    • webassembly_studio has a version comparing JS and C, available at WebAssembly Studio
    • codepen has 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.)

Author

Jason Tiscione

License

This project is licensed under the MIT License.

You can’t perform that action at this time.