Difference between revisions of "LSL Script Efficiency"

From Second Life Wiki
Jump to navigation Jump to search
Line 18: Line 18:


<pre>
<pre>
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) * 1000.0);
     return (integer) llGetSubString(stamp, 11, 12) * 3600000 + (integer) llGetSubString(stamp, 14, 15) * 60000 + llRound((float)llGetSubString(stamp, 17, -2) * 1000000.0)/1000;
}
}


Line 28: Line 27:
   state_entry() {
   state_entry() {
     float i = 0;
     float i = 0;
     float max = 10000;               // The larger the number here the better.
     float max = 10000;
     float current = time();
     float current = time();
     while (i < max) {
     while (i < max) {

Revision as of 20:08, 15 May 2007

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;
    }
    float t = (time()+-current)/max;
    llOwnerSay("The function in the loop took a total of " + (string)t + " milliseconds.");
  }
}

Efficiency

++a and a += 1 are equal in speed (they compile to the same bytecode). a++ is slower.