Difference between revisions of "Efficiency Tester"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}


Written by Xaviar Czervik, Modified by Strife Onizuka.
Written by [[User:Xaviar Czervik|Xaviar Czervik]], Modified by [[User:Strife Onizuka|Strife Onizuka]].


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

Revision as of 13:03, 22 May 2007

Written by Xaviar Czervik, Modified by Strife Onizuka.

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

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

Lots of people disagree with me that a += 1 is faster than +=a... If you don't like it, change it and then sue me :P.

//IMPORTANT: Only perform tests in an empty region to reduce contamination and be sure to wearing no attachments.

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;
//llInsertString(llDeleteSubString(stamp, 19, 19) + "000000", 23, ".")
}

default {
  state_entry() {
    //test variables
    float counter;

    //framework variables
    float i = 0;
    float j = 0;
    float max = 10000;
    float start = time();
    do {
      //test
      counter += 1;
      
    }while (++i < max);
    float delta = time();
    do ; while (++j < max);
    float end = time();//remove the time required by the framework
    float t = ((delta - start) - (end - delta))/max;
    llOwnerSay("The function in the loop took a total of " + (string)t + " milliseconds.");
  }
}