Difference between revisions of "Efficiency Tester"
(try the empty test of deleting the { counter += 1; } source line to see the astonishing inaccuracy of this instrument) |
m (tweak comments to provide consistent whitespace, preparatory to major edit) |
||
Line 10: | Line 10: | ||
<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. | // To reduce contamination and be sure to wearing no attachments. | ||
// Preferably do tests in a private sim with one on it. | // Preferably do tests in a private sim with one on it. | ||
Line 27: | Line 28: | ||
llOwnerSay((string) llGetFreeMemory()); | llOwnerSay((string) llGetFreeMemory()); | ||
//test variables | // test variables | ||
float counter; | float counter; | ||
//framework variables | // framework variables | ||
float i = 0; | float i = 0; | ||
float j = 0; | float j = 0; | ||
Line 38: | Line 39: | ||
do { | do { | ||
//test | // test | ||
counter += 1; | counter += 1; | ||
}while (++i < max); | } while (++i < max); | ||
float t1 = time(); | float t1 = time(); | ||
do ; while (++j < max); | do ; while (++j < max); | ||
float t2 = time();//remove the time required by the framework | float t2 = time(); // remove the time required by the framework | ||
float elapsed = ((t1 - t0) - (t2 - t1))/max; | float elapsed = ((t1 - t0) - (t2 - t1))/max; | ||
llOwnerSay("The function in the loop took a total of " + (string)elapsed + " milliseconds."); | llOwnerSay("The function in the loop took a total of " + (string)elapsed + " milliseconds."); |
Revision as of 05:37, 18 October 2007
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Q1: Want to see how small some code is?
A: 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.
Q2: Want to see how fast some code is?
A: Run your code inside code like this example to call your code time and again to measure the consequent change in llGetTimestamp.
// 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() { // count milliseconds since the day began string stamp = llGetTimestamp(); // "YYYY-MM-DDThh:mm:ss.ff..fZ" return (integer) llGetSubString(stamp, 11, 12) * 3600000 + // hh (integer) llGetSubString(stamp, 14, 15) * 60000 + // mm llRound((float)llGetSubString(stamp, 17, -2) * 1000000.0)/1000; // ss.ff..f } default { state_entry() { llOwnerSay((string) llGetFreeMemory()); // test variables float counter; // framework variables float i = 0; float j = 0; float max = 10000; // 2ms of work takes 20 seconds to repeat 10,000 times, plus overhead float t0 = time(); do { // test counter += 1; } while (++i < max); float t1 = time(); do ; while (++j < max); float t2 = time(); // remove the time required by the framework float elapsed = ((t1 - t0) - (t2 - t1))/max; llOwnerSay("The function in the loop took a total of " + (string)elapsed + " milliseconds."); } }
Launched by Xaviar Czervik, then modified by Strife Onizuka, then further edited as the history of this article shows.
Try the empty test of deleting the { counter += 1; } source line to see the astonishing inaccuracy of this instrument. The time cost of no code, as measured here, isn't always zero!
See the LSL Script Efficiency article for a less brief discussion. Please understand, we don't mean to be arguing for many different ways to measure the costs of code. Here we do mean to be building a consensus on best practices, in one considerately short article constructed from a neutral point of view.