collatz divide v bitshift right

JavaScript performance comparison

Test case created

Info

comparing divide by 2 versus bitshift right by 1 then multiply versus add

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var i=989345275647;//1348 steps
   
};
</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
divide by 2
for(i,c=0;i-1;i=i&1?3*i+1:i/2,c++);
 
pending…
bit shift right 1
for(i,c=0;i-1;i=i&1?3*i+1:i>>>1,c++);
 
pending…
add v multiply divide
for(i,c=0;i-1;i=i&1?i+i+i+1:i/2,c++);
 
pending…
add v multiply bitshift
for(i,c=0;i-1;i=i&1?i+i+i+1:i>>>1,c++);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment