Float to Int conversion comparison

JavaScript performance comparison

Revision 26 of this test case created by John Friend

Preparation code

<script>
// fill array with random decimal values
var coreNumbers = [];
var num = 1000;
var multiplier = 10;
for (var i = 0; i < num; i++) {
    if (i % 50 === 0) {
        multiplier *= 10;
    }
    coreNumbers[i] = Math.random() * multiplier;
}
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var testNumbers = coreNumbers.slice(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
for (var i = 0; i < testNumbers.length; i++) {
    testNumbers[i] = testNumbers[i] | 0;
}
pending…
Bitwise NOT
for (var i = 0; i < testNumbers.length; i++) {
    testNumbers[i] = ~~testNumbers[i];
}
pending…
Math.floor
for (var i = 0; i < testNumbers.length; i++) {
    testNumbers[i] = Math.floor(testNumbers[i]);
}
pending…
parseInt
for (var i = 0; i < testNumbers.length; i++) {
    testNumbers[i] = 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