Efficiency Tester

From Second Life Wiki
Jump to navigation Jump to search

This code will test the efficiency of what ever is in the while loop.

I've used i += 1 because it was found to be faster on the [LSL Script Efficiency]] page.

If you don't like it, sue me :P.

<math> a^b+c </math>

integer time() {

   string stamp = llGetTimestamp();
   return (integer) llGetSubString(stamp, 11, 12) * 3600000 + (integer) llGetSubString(stamp, 14, 15) * 60000 + llRound((float)llGetSubString(stamp, 17, -2) * 1000000.0)/1000;

}


default {

 state_entry() {
   float i = 0;
   float max = 10000;
   float current = time();
   while (i < max) {
     i += 1;
   }
   float t = (time()+-current)/max;
   llOwnerSay("The function in the loop took a total of " + (string)t + " milliseconds.");
 }

}