Rounding numbers down

JavaScript performance comparison

Revision 19 of this test case created by BigBossSNK

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  i = 0

};

Benchmark.prototype.teardown = function() {
  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
Math.floor
for (i = 0; i < 10000; i+=1.5){
Math.floor(i) // 3
}
pending…
parseInt
for (i = 0; i < 10000; i+=1.5){
parseInt(i, 10) // 3
}
pending…
Double bitwise NOT
for (i = 0; i < 10000; i+=1.5){
~~i // 3
}
pending…
Bitwise OR
for (i = 0; i < 10000; i+=1.5){
i | i // 3
}
pending…
Bitwise OR with 0
for (i = 0; i < 10000; i+=1.5){
i | 0 // 3
}
pending…
Bitwise AND
for (i = 0; i < 10000; i+=1.5){
i & i // 3
}
pending…
Bitwise left shift
for (i = 0; i < 10000; i+=1.5){
i << 0 // 3
}
pending…
toFixed
for (i = 0; i < 10000; i+=1.5){
i.toFixed() // 3
}
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