Difference between revisions of "Efficiency Tester"
(guess why this page thru yesterday mystically presented exactly the same code with less comments than the LSL Script Efficiency page) |
|||
Line 1: | Line 1: | ||
{{LSL Header}} | {{LSL Header}} | ||
Want to know how fast some code is? Run your code inside code like this example to call it time and again and measure the change in [[llGetTimestamp]]. | |||
Want to know how small some code is? Add three copies of your code to a script, call [[llGetFreeMemory]] to count free space, and start deleting copies. After deleting each copy, you should see a consistent savings in free space, ''i.e'', the code space cost of your code. | |||
Please understand, we don't mean to be arguing for many different ways to measure the costs of code. We do mean to be building a consensus on best practices, presented as a short discussion drawn from a neutral point of view. | |||
<pre> | <pre> | ||
//IMPORTANT: Only perform tests in an empty region | //IMPORTANT: Only perform tests in an empty region. | ||
// To reduce contamination and be sure to wearing no attachments. | |||
// Preferably do tests in a private sim with one on it. | |||
// Don't move while performing the test. | |||
// There is a margin of error so run the tests multiple times to determine it. | |||
integer time() { | integer time() { | ||
Line 44: | Line 46: | ||
</pre> | </pre> | ||
Copy-edited by [[User:Xaviar Czervik|Xaviar Czervik]], then modified by [[User:Strife Onizuka|Strife Onizuka]], then further edited as the history of this article shows. | |||
{{LSLC|Library}}{{LSLC|Examples}} | {{LSLC|Library}}{{LSLC|Examples}} |
Revision as of 04:24, 16 October 2007
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Want to know how fast some code is? Run your code inside code like this example to call it time and again and measure the change in llGetTimestamp.
Want to know how small some code is? Add three copies of your code to a script, call llGetFreeMemory to count free space, and start deleting copies. After deleting each copy, you should see a consistent savings in free space, i.e, the code space cost of your code.
Please understand, we don't mean to be arguing for many different ways to measure the costs of code. We do mean to be building a consensus on best practices, presented as a short discussion drawn from a neutral point of view.
//IMPORTANT: Only perform tests in an empty region. // To reduce contamination and be sure to wearing no attachments. // Preferably do tests in a private sim with one on it. // Don't move while performing the test. // There is a margin of error so run the tests multiple times to determine it. 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."); } }
Copy-edited by Xaviar Czervik, then modified by Strife Onizuka, then further edited as the history of this article shows.