LSL Script Efficiency: Difference between revisions
Jump to navigation
Jump to search
| Line 71: | Line 71: | ||
Amount of text (llSay() and Channel 1 used for all) | Amount of text (llSay() and Channel 1 used for all) | ||
<pre> | |||
1 Character: 1.242300 millis | 1 Character: 1.242300 millis | ||
10 Characters: 1.309700 millis | 10 Characters: 1.309700 millis | ||
100 Characters: 1.965600 millis | 100 Characters: 1.965600 millis | ||
</pre> | |||
Revision as of 20:39, 15 May 2007
| LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
What is Efficiency
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) * 1000000.0)/1000;
}
default {
state_entry() {
float i = 0;
float max = 10000;
float current = time();
while (i < max) {
i += 1;
}
float t = (time()+-current)/max;
llOwnerSay("The function in the loop took a total of " + (string)t + " milliseconds.");
}
}
Efficiency
In theory, ++a and a += 1 are equal in speed, however this is not true:
++a: 0.364700 millis a += 1: 0.346900 millis a++: 0.413700 millis
Testing the same function in for loops:
++a: 0.358370 millis a += 1: 0.351200 millis a++: 0.424600 millis
llOwnerSay v. llSay v. llShout v. llWhisper (Channel 0 where applies):
llOwnerSay(): 4.359000 millis llWhisper(): 5.201000 millis llSay(): 5.226000 millis llShout(): 14.877000 millis
Different Channels (llSay() Used for all):
-100000000: 1.226400 millis -100000: 1.254300 millis -100: 1.296100 millis -1: 1.292400 millis 0: 5.226000 millis 1: 1.242300 millis 100: 1.249100 millis 100000: 1.219700 millis 100000000: 1.228700 millis
Amount of text (llSay() and Channel 1 used for all)
1 Character: 1.242300 millis 10 Characters: 1.309700 millis 100 Characters: 1.965600 millis