Simple example of a performance comparison between a JavaScript and a C implementation of the Fibonacci sequence.
- Go to the fibonacci root directory.
- Build the WebAssembly module:
emcc fibonacci.c -o fibonacci.c.js -s EXPORTED_FUNCTIONS="['_fibonacciC']" -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -O3
- Check the build result.
- Go to the fibonacci root directory.
- Start a web server:
python -m http.server
- Check the console for the URL.
- Go to
http://[::]:8000/
in the browser. - Open the browser console.
- Call the JavaScript Fibonacci function:
Math.fibonacciJS(40);
- Call the C Fibonacci function:
Math.fibonacciC(40);
- Compare the results.