fib nomal vs asm.js (v8)

Revision 8 of this benchmark created on


Setup

function fibNomal(x) {
    if (x < 3) return 1;
    return fibNomal(x - 2) + fibNomal(x - 1);
  }
  
  function fibLikeAsm(x) {
    x = x | 0;
    if ((x | 0) < 3) return 1;
    return ((fibLikeAsm((x - 2) | 0) | 0) + (fibLikeAsm((x - 1) | 0) | 0)) | 0;
  }
  
  var fibUseAsm = (function () {

    'use asm';
    function fib(x) {
      x = x | 0;
      if ((x | 0) < 3) return 1;
      return ((fib((x - 2) | 0) | 0) + (fib((x - 1) | 0) | 0)) | 0;
    }
    return fib;
  })();

Test runner

Ready to run.

Testing in
TestOps/sec
fib 1 nomal heavy
fibNomal(30);
ready
fib 2 like asm heavy
fibLikeAsm(30);
ready
fib 3 use asm heavy
fibUseAsm(30);
ready
fib 4 nomal light
for(var i = 0; i < 200000; ++i) fibNomal(5);
ready
fib 5 like asm light
for(var i = 0; i < 200000; ++i) fibLikeAsm(5);
ready
fib 6 use asm light
for(var i = 0; i < 200000; ++i) fibUseAsm(5);
ready

Revisions

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