Float to Int conversion comparison

JavaScript performance comparison

Revision 29 of this test case created by Bergi

Preparation code

<script>
// fill array with random decimal valuesvar testNumbers = [];
var num = 1000;
var multiplier = 10;
for (var i = 0; i < num; i++) {
    if (i % 50 === 0) {
        multiplier *= 10;
    }
    testNumbers[i] = Math.random() * multiplier;
}
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var result;
  var i=0;

};
</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
Bitwise OR
i++; i%=num;
result = testNumbers[i] | 0;
pending…
Bitwise NOT
i++; i%=num;
result = ~~testNumbers[i];
pending…
Math.floor
i++; i%=num;
result = Math.floor(testNumbers[i]);
pending…
parseInt
i++; i%=num;
result = parseInt(testNumbers[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.

0 Comments