Skip to content

Latest commit

 

History

History

fibonacci

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

C vs JavaScript

Simple example of a performance comparison between a JavaScript and a C implementation of the Fibonacci sequence.

Getting Started

Prerequisites

Building

  1. Go to the fibonacci root directory.
  2. Build the WebAssembly module:
emcc fibonacci.c -o fibonacci.c.js -s EXPORTED_FUNCTIONS="['_fibonacciC']" -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -O3
  1. Check the build result.

Running

  1. Go to the fibonacci root directory.
  2. Start a web server:
python -m http.server
  1. Check the console for the URL.

Testing

  1. Go to http://[::]:8000/ in the browser.
  2. Open the browser console.
  3. Call the JavaScript Fibonacci function:
Math.fibonacciJS(40);
  1. Call the C Fibonacci function:
Math.fibonacciC(40);
  1. Compare the results.