float addition precision

JavaScript performance comparison

Revision 7 of this test case created by Michael Leaney

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var i, ints = [], floats1 = [], floats2 = [], sum;
   
    for (i = 0; i < 10000; i++) {
      ints.push((Math.random()*10).toFixed(0));
      floats1.push((Math.random()*10).toFixed(1));
      floats2.push((Math.random()*10).toFixed(5));
    }
   
    sum = function(arr) {
      var i, sum = 0;
      for (i = 0; i < arr.length; i++) {
        sum += arr[i];
      }
      return sum;
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
floats one digit
sum(floats1);
pending…
floats five digits
sum(floats2);
pending…
ints
sum(ints);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment