Euclids Algorithm, Do While Versus While

JavaScript performance comparison

Test case created by Josh Pearce

Info

Inspired by TAOCP Ex 1.1.3. Curious whether do whiles are faster than just whiles for this algorithm.

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Do While
var m;
var n=700;
var r=120;

do {
   m = n;
   n = r;
   r = m%n;
}
while (r !=0);
 
pending…
Continue
var m=700;
var n=120;

while(true) {
   m = m%n;
   if (m===0)
      break;
   n = n%m;
   if (n===0)
      break;

}
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