Math.floor vs bitwise-or 0

JavaScript performance comparison

Test case created by Joshua Conner

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var i, arr = [];
};
</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
Math.floor
for (i = 0; i < 100; i++) {
  arr[i] = Math.floor(Math.random() * 100);
}
pending…
Bitwise-or 0
for (i = 0; i < 100; i++) {
  arr[i] = (Math.random() * 100) | 0;
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment