Integer operations vs double operations

Benchmark created on


Setup

function fibDoubles(n) {
      var current = 0;
      var next = 1;
      for (var i = 0; i !== n; i = i + 1) {
        var nextNext = current + next;
        current = next;
        next = nextNext;
      }
      return current;
    }
    
    function fibInts(n) {
      var current = 0;
      var next = 1;
      for (var i = 0; i !== n; i = i + 1 | 0) {
        var nextNext = current + next | 0;
        current = next;
        next = nextNext;
      }
      return current;
    }
    
    function fibInts2(n) {
      n = n | 0;
      var current = 0;
      var next = 1;
      for (var i = 0; i !== n; i = i + 1 | 0) {
        var nextNext = current + next | 0;
        current = next;
        next = nextNext;
      }
      return current;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
doubles
if (fibDoubles(45) !== 1134903170)
  throw new Error("failed");
ready
ints
if (fibInts(45) !== 1134903170)
  throw new Error("failed");
ready
ints 2
if (fibInts2(45) !== 1134903170)
  throw new Error("failed");
ready

Revisions

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