evenodd

JavaScript performance comparison

Test case created by 2x2p

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  /* make an array with 10.000 random numbers */
  var array = [];
  while(array.length<10000){
    array.push(parseInt(100*Math.random()));
  }
  
  /* test all numbers style 1 by division comparison */
  function checkOdd1(_int){
    return (_int/2)==parseInt(_int/2);
  }
  
  /* test all numbers style 2 for odd modulus division */
  function checkOdd2(_int){
    return _int % 2;
  }
  
  /* test all numbers style 3 for being odd bitwise */
  function checkOdd3(_int){
    return _int & 1;
  }
  

};
</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
style 3 bitwise
var result = [];

for (var i = 0, len = array.length; i < len; i++) {
  result[i] = checkOdd3(array[i]);
}
pending…
style 1 comparison
var result = [];

for (var i = 0, len = array.length; i < len; i++) {
  result[i] = checkOdd1(array[i]);
}
pending…
style 2 modulus
var result = [];

for (var i = 0, len = array.length; i < len; i++) {
  result[i] = checkOdd2(array[i]);
}
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