Test for even or odd

JavaScript performance comparison

Test case created by ThinkingStiff

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var x, y;
   
};
</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
%
x = 1;
if( x % 2 ) { y = x }; //if odd
if( !( x % 2 ) ) { y = x }; //if even
x = 0;
if( x % 2 ) { y = x };
if( !( x % 2 ) ) { y = x };
x = -1;
if( x % 2 ) { y = x };
if( !( x % 2 ) ) { y = x };
 
pending…
&
x = 1;
if( ( x & 1 ) ) { y = x }; //if odd
if( !( x & 1 ) ) { y = x }; //if even
x = 0;
if( ( x & 1 ) ) { y = x };
if( !( x & 1 ) ) { y = x };
x = -1;
if( ( x & 1 ) ) { y = x };
if( !( x & 1 ) ) { y = x };
 
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