Difference between revisions of "Efficiency Tester"
Jump to navigation
Jump to search
m |
|||
Line 1: | Line 1: | ||
{{LSL Header}} | {{LSL Header}} | ||
Written by Xaviar Czervik, Modified by Strife Onizuka. | |||
This code will test the efficiency of what ever is in the while loop. | |||
Lots of people disagree with me that a += 1 is faster than +=a | 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. | |||
<pre> | <pre> | ||
//IMPORTANT: Only perform tests in an empty region to reduce contamination and be sure to wearing no attachments. | |||
integer time() { | integer time() { | ||
string stamp = llGetTimestamp(); | 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; | 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 { | default { | ||
state_entry() { | state_entry() { | ||
//test variables | |||
float counter; | |||
//framework variables | |||
float i = 0; | float i = 0; | ||
float j = 0; | |||
float max = 10000; | float max = 10000; | ||
float | float start = time(); | ||
while (i < max) | do { | ||
//test | |||
counter += 1; | |||
float t = ( | |||
}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."); | llOwnerSay("The function in the loop took a total of " + (string)t + " milliseconds."); | ||
} | } |
Revision as of 10:46, 21 May 2007
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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."); } }