fib-asmjs

JavaScript performance comparison

Test case created by kazuho

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var testArgs = [];
  for (var i = 0; i != 1000; ++i) {
    testArgs[i] = ((i % 25) + 20) | 0;
  }
  
  function MyModule() {

    "use asm";
  
    function fib(n) {
      n = n | 0;
      var value = 1;
      var prev = 1;
      var i = 1;
      var t = 0;
      for (;
        (i | 0) < (n | 0); i = (i + 1) | 0) {
        t = prev;
        prev = value;
        value = (value + t) | 0;
      }
      return value | 0;
    }
    return {
      fib: fib
    };
  }
  var myModule = MyModule();

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
original
return (function() {
  function fib(n) {
    var value = 1,
      prev = 1;
    for (var i = 1; i < n; ++i) {
      var t = prev;
      prev = value;
      value += t;
    }
    return value;
  }
  var sum = 0;
  for (var i = 0; i != testArgs.length; ++i) {
    sum += fib(testArgs[i]);
  }
  return sum;
})();
pending…
core-int
return (function() {
  function fib(n) {
    var value = 1,
      prev = 1;
    for (var i = 1; i < n; ++i) {
      var t = prev;
      prev = value;
      value = (value + t) | 0;
    }
    return value;
  }
  var sum = 0;
  for (var i = 0; i != testArgs.length; ++i) {
    sum += fib(testArgs[i]);
  }
  return sum;
})();
pending…
all-int
return (function() {
  function fib(n) {
    n = n | 0;
    var value = 1,
      prev = 1;
    for (var i = 1; i < n; i = (i + 1) | 0) {
      var t = prev;
      prev = value;
      value = (value + t) | 0;
    }
    return value;
  }
  var sum = 0;
  for (var i = 0; i != testArgs.length; ++i) {
    sum += fib(testArgs[i]);
  }
  return sum;
})();
pending…
asm.js
return (function() {
  var fib = myModule.fib;
  var sum = 0;
  for (var i = 0; i != testArgs.length; ++i) {
    sum += fib(testArgs[i]);
  }
  return sum;
})();
pending…

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

Compare results of other browsers

0 Comments