Fibonacci WebAssembly vs JavaScript

Benchmark created on


Setup

/*
double
fibonacci(int n) {
    if (n <= 1)
        return 1;

    return fibonacci(n - 1) + fibonacci(n - 2);
}
*/

const wasm_bin = Uint8Array.from(
[0,97,115,109,1,0,0,0,1,6,1,96,1,127,1,124,
3,2,1,0,5,3,1,0,2,6,8,1,127,1,65,128,136,4,
11,7,22,2,6,109,101,109,111,114,121,2,0,9,
102,105,98,111,110,97,99,99,105,0,0,10,54,1,
52,1,1,124,68,0,0,0,0,0,0,240,63,33,1,2,64,
32,0,65,1,76,13,0,32,0,65,127,106,16,128,128,
128,128,0,32,0,65,126,106,16,128,128,128,128,
0,160,33,1,11,32,1,11,0,39,4,110,97,109,101,1,
12,1,0,9,102,105,98,111,110,97,99,99,105,7,18,
1,0,15,95,95,115,116,97,99,107,95,112,111,105,
110,116,101,114,0,45,9,112,114,111,100,117,99,
101,114,115,1,12,112,114,111,99,101,115,115,
101,100,45,98,121,1,12,85,98,117,110,116,117,
32,99,108,97,110,103,6,49,52,46,48,46,54]
);

const wasm_module = new WebAssembly.Module(wasm_bin);

const wasm_instance = new WebAssembly.Instance(wasm_module);

const fibonacci_wasm = wasm_instance.exports.fibonacci;

function fibonacci(n) {
  if (n <= 1)
    return 1;
  return fibonacci(n-1) + fibonacci(n-2);
}

Test runner

Ready to run.

Testing in
TestOps/sec
WebAssembly
fibonacci_wasm(5)
ready
JavaScript
fibonacci(5)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.