Git Product home page Git Product logo

webassembly-wave's Introduction

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.

webassembly-wave's People

Contributors

jtiscione avatar maxgraey avatar jason-rovitracker avatar gregzanch avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.