LSL Script Efficiency: Difference between revisions
Jump to navigation
Jump to search
m Stub |
No edit summary |
||
| Line 20: | Line 20: | ||
<pre> | <pre> | ||
integer time() { | |||
string stamp = llGetTimestamp(); | |||
return (integer) llGetSubString(stamp, 11, 12) * 3600000 + (integer) llGetSubString(stamp, 14, 15) * 60000 + llRound((float) llGetSubString(stamp, 17, -2) * 1000.0); | |||
} | |||
default { | default { | ||
state_entry() { | state_entry() { | ||
float i = 0; | |||
while (i < | float max = 1000; | ||
float current = time(); | |||
while (i < max) { | |||
++a; | ++a; | ||
} | } | ||
llOwnerSay("The function tool a total of " + (string)((time()-current)/max)) + " milliseconds."); | |||
} | } | ||
} | } | ||
| Line 32: | Line 43: | ||
</div></div> | </div></div> | ||
<div id="box"> | <div id="box"> | ||
== Efficiency == | == Efficiency == | ||
<div style="padding: 0.5em;"> | <div style="padding: 0.5em;"> | ||
Revision as of 18:59, 15 May 2007
| LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
What is Efficiency
PAGE UNDER CONSTRUCTION!
Efficiency is how long it takes to run a script.
There are many ways to speed up scripts, such as using ++a instead of a++.
Rules for posting
The following code snipit will allow testing of a function.
integer time() {
string stamp = llGetTimestamp();
return (integer) llGetSubString(stamp, 11, 12) * 3600000 + (integer) llGetSubString(stamp, 14, 15) * 60000 + llRound((float) llGetSubString(stamp, 17, -2) * 1000.0);
}
default {
state_entry() {
float i = 0;
float max = 1000;
float current = time();
while (i < max) {
++a;
}
llOwnerSay("The function tool a total of " + (string)((time()-current)/max)) + " milliseconds.");
}
}
Efficiency
++a and a += 1 are equal in speed (they compile to the same bytecode). a++ is slower.