float addition precision

JavaScript performance comparison

Revision 6 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var ints = [];
    var floats = [];
    var floats2 = [];
   
    for (var i = 1; i < 1000; i++) {
        ints.push(1 + (Math.random() * 10 | 0));
        floats.push(+(Math.random() * 10).toFixed(2));
        floats2.push(Math.random() * 10);
    }
   
    var sum = 1;
};

Benchmark.prototype.teardown = function() {
    sum = 1;
};
</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
int — +
sum = 1;
for (var i = 0; i < 1000; i++) {
  sum += ints[i];
}
pending…
short floats — +
sum = 1;
for (var i = 0; i < 1000; i++) {
  sum += floats[i];
}
pending…
long floats — +
sum = 1;
for (var i = 0; i < 1000; i++) {
  sum += floats2[i];
}
pending…
int — *
sum = 1;
for (var i = 0; i < 1000; i++) {
  sum *= ints[i];
}
pending…
short floats — *
sum = 1;
for (var i = 0; i < 1000; i++) {
  sum *= floats[i];
}
pending…
long floats — *
sum = 1;
for (var i = 0; i < 1000; i++) {
  sum *= floats2[i];
}
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