Speed Tester

From Second Life Wiki
Revision as of 09:46, 18 March 2010 by Bobbyb30 Swashbuckler (talk | contribs) (→‎Speed Tester.lsl: Added option to drop first trial, fixed minor bug for multiple trials)
Jump to navigation Jump to search

Description

The following script is used for testing the speed of LSL snippets. The script was written in LSLEditor. The script should work fine in both mono & LSO.

Creator

Contributors

Add yourself here if you change this script.

License

This script is released into Public Domain.

Disclaimer

These programs are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Directions

Go to an empty/script free private sim and detach any of your scripted attatchments. Create an object and place this script inside. Modify the "test()" and "clearvariables()" with whatever code it is that you want to test. Set the number of trials, the testcounter, and the test name. Save the script. Touch the object to begin the test. (If the script takes too long, reset).

The script provides min, max, avg, median, total time, and standard deviation.

You may need to run multiple trials as the script as all of SL is not always accurate/predictabl

Speed Tester.lsl

<lsl> //*********************************************************************************************************** // * // --Speed Tester-- * // * //*********************************************************************************************************** // www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano) //Creator: Bobbyb30 Swashbuckler //Attribution: none //Created: December 1, 2008 //Last Modified: March 18, 2010 //Released: Wed, March 17, 2010 //License: Public Domain //Status: Fully Working/Production Ready //Version: 1.1.6 //LSLWiki: https://wiki.secondlife.com/wiki/Speed_tester

//Name: Speed Tester.lsl //Purpose: To test the speed of certain LSL snippets. //Technical Overview: Uses 2 loops, one for trials, one for the test counter //Directions: This is meant to be used by scripters, it should be easy to use. Modify the test() with your snippet, and touch to begin the test.

//Compatible: Mono & LSL compatible //Other items required: None //Notes: If it takes too long, simply reset. // Do the test in an empty region, with as few script as possible to prevent contamination. (Make sure you aren't // wearing scripted attatchments). // This test is not 100% accurate, but it should give you a good idea as to whether or not something is faster. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//User modifiable variables integer trials = 20;//how many trials to conduct integer testcounter = 200000;//how many times to conduct the test string testname = "speed";//what to call your test, optional integer discardfirsttrial = FALSE;//whether or not to discard the first trial...this can be slower as the script is loaded into the VM for the 1st time following a save

//// //declare any of your global variables here integer x;

test()//in here goes the test {

   ++x;

}

//insert the variables you want to clear after each trial clearvariables() {

   x = 0;

} ///////////////////////////////////////////////////////////////////////////////////////

//do not modify below ////////////////////////// //global variables...do not modify, except to change whether or not to round list times;//the list of times, do not modify this one

float standarddeviation(list inputlist)//calculates the standard deviation of the times list {

   //http://en.wikipedia.org/wiki/Standard_deviation
   float mean = (llListStatistics(LIST_STAT_MEAN,inputlist)/(float)testcounter);//get the mean
   integer timeslistlength = llGetListLength(times);//get times length
   integer counter;

   float sumofdifferencesquared;
   do
   {
       float differencesquared = (llList2Float(times,counter)/(float)testcounter) - mean;
       differencesquared = differencesquared * differencesquared;//*=differencesquared square it
       sumofdifferencesquared += differencesquared;
   }while(++counter < timeslistlength);

   return llSqrt(sumofdifferencesquared/timeslistlength);

}


default {

   state_entry()
   {
       llOwnerSay("Speed Tester.lsl' released into Public Domain by Bobbyb30 Swashbuckler (C) 2009");
       if(llStringTrim(testname,STRING_TRIM) != "")//if testname isn't empty, print out test name
           llOwnerSay("Touch to begin the '" + testname + "' test.");
   }

   touch_start(integer total_number)
   {
       //print out the headers
       llOwnerSay("\n \n=================================================================================");//break
       if(llStringTrim(testname,STRING_TRIM) != "")//if testname isn't empty, print out test name
           llOwnerSay("Running the '" + testname + "' test.");
       else
           llOwnerSay("Running the test.");

       llOwnerSay("Start Time:" + llGetTimestamp());
       
       times = [];//reset the times


       ///////
       //the actual test loop
       integer counter;
       integer trialscounter;

       do//the trial loop
       {

           clearvariables();//clear user variables before each test
           counter = 0;//reset counter for testcounter before each trial
           llResetTime();//Reset time before each trial
           do//the test counter loop
           {
               test();//the test to perform
           }while(++counter < testcounter);//the test counter loop
           times += llGetTime();//add the trial time to the list
           //above you can determine whether to add llRound, (integer) before llGetTime(), or leave as float for more accuracy                   


       }while(++trialscounter < trials);//the trial loop
       /////////////
       
       if(discardfirsttrial)//whether or not to delete the first trial
       {
           times = llDeleteSubList(times,0,0);//delete from list
           --trials;//one less trial
       }

       llOwnerSay("---------");
       llOwnerSay("Test: " + testname + " Complete.");
       llOwnerSay("Number of trials: " + (string)trials);
       if(discardfirsttrial)//whether or not to delete the first trial
           llOwnerSay("...First trial was deleted.");
       llOwnerSay("Testcounter: " + (string)testcounter);
       llOwnerSay("Trial times: " + llList2CSV(times));
       llOwnerSay("----------");

       //print out results
       llOwnerSay("End Time:" + llGetTimestamp());
       llOwnerSay("Total test time: " + (string)llListStatistics(LIST_STAT_SUM,times) + " seconds.");
       llOwnerSay("Min: " + (string)(llListStatistics(LIST_STAT_MIN,times)/(float)testcounter));//minimum time
       llOwnerSay("Avg: " + (string)(llListStatistics(LIST_STAT_MEAN,times)/(float)testcounter));//average time
       llOwnerSay("Median: " + (string)(llListStatistics(LIST_STAT_MEDIAN,times)/(float)testcounter));//median time
       llOwnerSay("Max: " + (string)(llListStatistics(LIST_STAT_MAX,times)/(float)testcounter));//maximum time
       llOwnerSay("Range: " + (string)(llListStatistics(LIST_STAT_RANGE,times)/(float)testcounter));//average time
       llOwnerSay("Standard Deviation: " + (string)standarddeviation(times));//standard deviation
       if(llStringTrim(testname,STRING_TRIM) != "")//if testname isn't empty, print out test name
           llOwnerSay("END OF '"+ testname + "' TEST");
       else
           llOwnerSay("END OF TEST");
       llOwnerSay("=========================================================================");
   }

} </lsl>

Sample Output

[10:53]  Object: Speed Tester.lsl' released into Public Domain by Bobbyb30 Swashbuckler (C) 2009
[10:53]  Object: Touch to begin the 'speed' test.
[10:53]  Object: 
 
=================================================================================
[10:53]  Object: Running the 'speed' test.
[10:53]  Object: Start Time:2010-03-17T17:53:53.937185Z
[10:53]  Object: ---------
[10:53]  Object: Test: speed Complete.
[10:53]  Object: Number of trials: 20
[10:53]  Object: Testcounter: 5000
[10:53]  Object: Trial times: 0.493176, 0.313669, 0.226103, 0.177510, 0.227335, 0.280155, 0.133290, 0.156750, 0.135822, 0.134886, 0.179554, 0.179353, 0.190092, 0.133380, 0.134380, 0.112274, 0.134281, 0.112140, 0.135817, 0.190169
[10:53]  Object: ----------
[10:53]  Object: End Time:2010-03-17T17:53:57.749087Z
[10:53]  Object: Total test time: 3.780136 seconds.
[10:53]  Object: Min: 0.000022
[10:53]  Object: Avg: 0.000038
[10:53]  Object: Median: 0.000033
[10:53]  Object: Max: 0.000099
[10:53]  Object: Range: 0.000076
[10:53]  Object: Standard Deviation: 0.000018
[10:53]  Object: END OF 'speed' TEST
[10:53]  Object: =========================================================================

Other

If you find this script of use, please do let me know=D.