Loop Optimization
CSGNetwork FREE Source Code, Javascript Source, and Code Snippets!
CSGNetwork Custom Search
Bookmark and Share
 
CSGNetwork
Snippets
Calculators
Home
Back



Right click this window and select "view source" in order to copy the source for this script.

Loop Optimization

Standard Faster Fastest

Start Time

End Time

Elapsed Time

Result

Start Time

End Time

Elapsed Time

Result

Start Time

End Time

Elapsed Time

Result


Number Of Loop Iterations


function doStandard()
{
   /* common code */

   for (l=1;l<iterations+1;l++)
   {
      testVal++;
   }

   /* common code */
}
	
function doFast()
{
   /* common code */

   l = iterations;
   do
   {
      testVal++;
   } while (--l);

   /* common code */
}
	
function doFastest()
{
   /* common code */

   n = iterations % 8;
   while (n--)
   {
      testVal++;
   }

   n = parseInt(iterations/8);
   while (n--)
   {
      testVal++;
      testVal++;
      testVal++;
      testVal++;
      testVal++;
      testVal++;
      testVal++;
      testVal++;
   }

   /* common code */
}
	


Bookmark and Share
Registered® Trademark™ and CopyrightŠ 1973 - CSG, Computer Support Group, Inc. and CSGNetwork.Com All Rights Reserved