SphereCommunity
What is faster ? - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: What is faster ? (/Thread-What-is-faster)



What is faster ? - darksun84 - 05-22-2013 02:49 AM

Premise :
Values are "fixed", they range from 0 to 1000 with increments of 100.
What will be the faster way for sphere to assign a bonus that depends on those fixed "numbers" ?

PHP Code:
// Method 1 : A simple math formula
local.bonus = (<value> / 100)  * 3


// Method 2 : Using defnames
[DEFNAME bonus_calc]
bonus_0    0
bonus_100 3
bonus_200 6
bonus_300 9
bonus_400 12
..
bonus_1000 30

local
.bonus = <def.bonus_<value>> 
I think that the first seems faster Blush

Also i can't test it right now with the script profiler Shock


RE: What is faster ? - Gil Amarth - 05-22-2013 03:46 AM

I think second is marginally faster, but anyways two boths methods are pretty fast, the difference is almost zero.

I´ll use the first only for simplicity.


RE: What is faster ? - Wap - 05-22-2013 11:16 PM

Code:
[FUNCTION TESTSCPSPEED]
LOCAL.T=<SERV.RTICKS>
FOR I 0 <ARGV[0]>
    ...
ENDFOR
SYSMESSAGE @89,,1 Loop Time=<EVAL <SERV.RTICKS>-<LOCAL.T>>
RETURN 1



RE: What is faster ? - darksun84 - 05-22-2013 11:30 PM

Nice i'll try that Big Grin ,

How much is reliable compared to the built in script profiler ?


RE: What is faster ? - Gil Amarth - 05-23-2013 01:21 AM

I have tried, it´s faster method 1...