Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » Finished MUD Scripts
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Tue Oct 22, 2002 12:31 pm   

Stopwatch - precise timing
 
This is one of the most useful scripts I've ever had. While I made it for Achaea, it is useful for any mud.

What it does is time the interval between two preset outputs from your mud, stores that value in a stringlist, and after you feel you have enough, outputs the mean time and a few other useful things.

Is slashing with a battleaxe just as fast as mauling? Is a longsword better than a broadsword? Just how long does it take for...


#CLASS {General|Stopwatch}
#ALIAS viewstats {totalval=0;#FORALL @timerec {#ADD totalval %float( %i)};#ECHO %ansi( 12) Stopwatch Statistics;#ECHO Replication: %numitems( @timerec);#ECHO Mean Time: %leftback( %eval( @totalval/%numitems( @timerec)/1000.0), %eval( %pos( ".", %eval( @totalval/%numitems( @timerec)/1000.0))+9)) secs;#ECHO Mean Time "(1 dec place)": %leftback( %eval( @totalval/%numitems( @timerec)/1000.0), %eval( %pos( ".", %eval( @totalval/%numitems( @timerec)/1000.0))+11)) secs;#ECHO Min Time: %min( %replace( @timerec, "|", ",")) secs, Max Time: %max( %replace( @timerec, "|", ",")) secs}
#ALIAS stopwatchon {#ECHO Stopwatch ON;#STATE stopwatch 1}
#ALIAS stopwatchoff {#STATE stopwatch 0;#ECHO Stopwatch OFF}
#ALIAS setstart {starttrig={%-1};timerec=%null}
#ALIAS setstop {stoptrig={%-1}}
#VAR starttrig {You strike out at Vorleth with your deadly tail, and sting him.}
#VAR timerec {2200|1930|2040}
#VAR stoptrig {recovered balance}
#VAR totalval {6170}
#TRIGGER "stopwatch" {This is a Stopwatch Trigger} {} "" {manual}
#COND "stopwatch" {@starttrig} {starttime=%secs}
#COND "stopwatch" {@stoptrig} {#ECHO Time: %eval( %secs-@starttime);#ADDITEM timerec %eval( %secs-@starttime);#STATE stopwatch 1} {manual}
#CLASS 0


Instructions in the next reply.



Caled
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Tue Oct 22, 2002 12:44 pm   
 
Now for instructions. As you can see by looking at the values in the variables, that last time I used this script was to test the speed of stinging, and the unlucky crash-dummy was Vorleth. I also stopped after 3 stings, meaning I probably got distracted and never finished the test. I'll use this test as an example.

To set up that test, I first had to know:
(1) The "start" trigger.
(2) The "stop" trigger.

Knowing these, I then had to set them. To do this, I typed:
setstart You strike out at Vorleth with your deadly tail, and sting him.
setstop recovered balance

Having done that, I had to begin it with:
stopwatchon

Then, all I had to do was to sting Vorleth a few times, and when i thought I had enough to get a meaningful average, run the "viewstats" alias.

"stopwatchoff" turns it off.

Problems with the "viewstats" results

(1) Periods of rare but extreme lag, cause large values (outliers) to be added to the script, causing a misleadingly high average to be calculated.

(2) Since the mud itself has an exact time that the skill should take (additional time caused by in-game lag), the -minimum- time is really pretty important, so keep that in mind, since it represents the time taken when there was least lag.

(3) Out-game lag in spikes can cause unusually high times, but it can also, in theory, cause extremely low ones, though I havn't seen it happen. Still, bear that in mind. If out-game lag is constant, then no effect on the times should occur.


If anyone has a way to test for outliers and discard them, please mention it.

Caled
Reply with quote
jlaxson
Beginner


Joined: 20 Oct 2002
Posts: 29

PostPosted: Wed Oct 23, 2002 6:28 am   
 
Outlier Processing

I added it. When VIEWSTATS is running it floors cpu usages while intensive calculations are done, but it seems pretty accurate for my sake.

What you should know about this script:
To change the Outlier-Threshold (The distance a time must be outside of an average of all the other times), use the TIMETHRESHOLD variable. The lower the number, in milliseconds, the closer a time must be to the norm to be counted.
To disable Outlier Processing, change OUTLIERCOUNT to a number that's more than 1. When set to 1, outliers will be weeded out (But know this, it will still process them, just not include in results). A number lower than one will not count any results.

Here's the script:

-- BEGIN OUTLIER STOPWATCH --
#CLASS {General|Stopwatch}
#ALIAS viewstats {#SAY "";#SAY ----- Calculating Data...Please Wait -----;totalval=0;#VAR workingcount 0;#VAR goodtimes "";#FORALL @timerec {#ADD totalval %float( %i)};#VAR times "";#FORALL @timerec {#VAR times %addkey( @times, %i, 0);#NOOP Blah};#SAY Please wait...processing data.;#LOOPDB @times {#VAR testing "";#LOOP %numitems( @timerec) { #IF (%item( @timerec, %i) != %key) { #VAR testing %additem( %item( @timerec, %i), @testing)}};#VAR temptotal 0;#ADD workingnum 1;#IF (%mod( @workingnum, 2) = 0) {#SAY Please wait...processing data.};#FORALL @testing {#ADD temptotal %float( %i)};#VAR tempavg %eval( @temptotal / (%numitems( @timerec) - 1));#IF (%min( %max( %key, %eval( @tempavg - @timethreshold)) , %eval( @tempavg + @timethreshold)) != %key) {#VAR times %addkey( @times, %key, %eval( %val + 1))}};#LOOPDB @times {#IF (%val < @outliercount) {#VAR goodtimes %additem( %key, @goodtimes)}};#VAR totalval 0;#FORALL @goodtimes {#ADD totalval %i};#SAY ---- Done! ----;#ECHO "";#ECHO %ansi( 12)---- Stopwatch Statistics ----;#ECHO Replication: %numitems( @goodtimes);#ECHO Mean Time: %leftback( %eval( @totalval/%numitems( @goodtimes)/1000.0), %eval( %pos( ".", %eval( @totalval/%numitems( @goodtimes)/1000.0))+9)) secs;#ECHO Mean Time "(1 dec place)": %leftback( %eval( @totalval/%numitems( @goodtimes)/1000.0), %eval( %pos( ".", %eval( @totalval/%numitems( @goodtimes)/1000.0))+11)) secs;#ECHO Min Time: %min( %replace( @goodtimes, "|", ",")) secs, Max Time: %max( %replace( @goodtimes, "|", ",")) secs;#ECHO Number of Outliers: %eval( %numitems( @timerec) - %numitems( @goodtimes));#NOOP Clean Up;#UNVAR tempavg;#UNVAR goodtimes;#UNVAR totalval;#SEND %lf}
#ALIAS stopwatchon {#ECHO Stopwatch ON;#STATE stopwatch 1}
#ALIAS stopwatchoff {#STATE stopwatch 0;#ECHO Stopwatch OFF}
#ALIAS setstart {starttrig={%-1};timerec=%null}
#ALIAS setstop {stoptrig={%-1}}
#VAR starttrig {menacing stance}
#VAR workingcount {0} {0}
#VAR timethreshold {300}
#VAR outliercount {1}
#VAR timerec {}
#VAR stoptrig {recovered balance}
#VAR totalval {}
#VAR goodtimes {}
#VAR times {}
#VAR tempavg {2190}
#TRIGGER "stopwatch" {This is a Stopwatch Trigger} {} "" {manual}
#COND "stopwatch" {@starttrig} {starttime=%secs}
#COND "stopwatch" {@stoptrig} {#ECHO Time: %eval( %secs-@starttime);#ADDITEM timerec %eval( %secs-@starttime);#STATE stopwatch 1} {manual}
#CLASS 0

-- END OUTLIER STOPWATCH --

Enjoy!
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Sun Sep 18, 2005 12:46 am   bugfix
 
I found this bug in it years ago, and forgot to post the change here. Essentially, an #ADDITEM was used where it should have been an %additem

#ALIAS setstop {stoptrig={%-1}} "General|Stopwatch"
#ALIAS stopwatchon {#ECHO Stopwatch ON;#STATE stopwatch 1} "General|Stopwatch"
#ALIAS viewstats {totalval=0;#FORALL @timerec {#ADD totalval %float( %i)};#ECHO %ansi( 12) Stopwatch Statistics;#ECHO Replication: %numitems( @timerec);#ECHO Mean Time: %leftback( %eval( @totalval/%numitems( @timerec)/1000.0), %eval( %pos( ".", %eval( @totalval/%numitems( @timerec)/1000.0))+9)) secs;#ECHO Mean Time "(1 dec place)": %leftback( %eval( @totalval/%numitems( @timerec)/1000.0), %eval( %pos( ".", %eval( @totalval/%numitems( @timerec)/1000.0))+11)) secs;#ECHO Min Time: %min( %replace( @timerec, "|", ",")) secs, Max Time: %max( %replace( @timerec, "|", ",")) secs} "General|Stopwatch"
#ALIAS stopwatchoff {#STATE stopwatch 0;#ECHO Stopwatch OFF} "General|Stopwatch"
#ALIAS setstart {starttrig={%-1};timerec=%null} "General|Stopwatch"
#VAR starttime {42114286} {_nodef} "General|Stopwatch"
#VAR timerec {15843|2274|28251|2193} {_nodef} "General|Stopwatch"
#TRIGGER "stopwatch" {This is a Stopwatch Trigger} {} "General|Stopwatch" {manual}
#COND {@starttrig} {starttime=%secs}
#COND {@stoptrig} {timerec=%additem( %eval( %secs-@starttime), @timerec);#ECHO Time: %eval( %secs-@starttime) Reps: %numitems( @timerec);#STATE stopwatch 1} {manual}
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » Finished MUD Scripts All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net