 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Mon Apr 16, 2007 3:10 am
Interesting Performance Numbers |
I was running some performance tests to see which would be faster.
We all know Local variables are faster than regular variables. But I have a calculation that uses a constant database variable. What's cool is that you can copy the the database variable to a local variable, but you still can't use the dot-notation to get the value. In other words you can do @DB.value but not $DB.value. I remembered I could used %db on database variables and it worked on local variables, so I wanted to see which would perform faster.
I ran 3 scenarios:
zMUD Version - Doing it the zMUD way with all regular variables
CMUD v1 - Using local variables to do the calculations against my DB variable constant
CMUD v2 - Using local variables to do the calculations with a call to %db to get the database variable.
Here is the code I ran
Code: |
#LOCAL $localMoney, $Temp, $Temp2
#VAR Temp3 0
$Loops = 1000
$localMoney=@Money
$start=%secs
#LOOP $Loops {
Temp3=($param * @Money.Sunburst* %random(1,100))
}
$stop=%secs
#ECHO ZMUD Done in ($stop - $start) milliseconds with $Loops loops done.
$start=%secs
#LOOP $Loops {
$Temp=($param *@Money.Sunburst * %random(1,100))
}
$stop=%secs
#ECHO Local Variable Calc Done in ($stop - $start) milliseconds
$start=%secs
#LOOP $Loops {
$Temp2=($param * %db($localMoney,Sunburst) * %random(1,100))
}
$stop=%secs
#ECHO All Local Variable with Func call Calc Done in ($stop - $start) milliseconds
|
I introduced the %random as a means of varying the calculations a bit, just to make things a bit more interesting and do away with some of the effects of underlying caching.
The results were as follows:
Code: |
Run 1 Run 2 Run 3 Run 4 Run 5 Avg
Loop 1000
zMUD version 141 109 125 125 125 125
CMUD v1 16 31 32 31 16 25.2
CMUD v2 16 16 15 16 31 18.8
Loop 10000
zMUD version 734 1984 781 781 766 1009.2
CMUD v1 203 219 187 203 187 199.8
CMUD v2 235 250 235 235 250 241
Loop 100000
zMUD version 7329 7203 19688 11406.67
CMUD v1 2000 2031 2015 2015.333
CMUD v2 2359 2922 2391 2557.333
|
The results you see here are in milliseconds.
Although it surprised me at first, it makes sense that v2 of the CMUD test would run slower than v1. Even though were are using local variables, in the long run the overhead of making function calls must be greater than just using the regular variable.
The other interesting thing to note is that some of the runs have significant spikes. Most notably Run 3 of zMUD at 100,000; Run 2 of CMUD v2 at 100,000; and Run 2 of zMUD at 10,000. I'm not sure the reason for this (I wasn't doing anything in the background on the PC). It can be dismissed as a general computing anomaly, but I wonder if it is not influenced by the background updating and saving thats being down.
What intrigued me most, is that lowest loop counts seemed to perform better. But if you can you consider any 30+ milliseconds runs of CMUD at 1000 as smaller manifestations of the spikes mentioned above, then it really doesn't make a difference what you use as long as you use local variables to store you results. |
|
_________________ Asati di tempari! |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Apr 23, 2007 11:59 pm |
I thought I'd add an addendum to this now that the $localkey.value syntax is in - using that instead of %db shaves a little off the CMUD v1 speed at high loop numbers - only about .05-.1 seconds, though.
|
|
|
 |
|
|
|
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
|
|