- Joined
- Jun 23, 2007
- Messages
- 4,066
Why are constant integers 5% slower (when in a comparison) than regular globals, yet booleans are about the same?
Any theories
Any theories
scope Benchmark initializer Init
globals
private constant integer ITERATIONS = 8191
private trigger t = CreateTrigger()
private integer Int = 0
private constant integer CONST_INT = 0
endglobals
private function Actions takes nothing returns nothing
local integer curLoop
local integer sw
local real array result
call DisableTrigger(t)
call BJDebugMsg("\n\n")
// TEST 1
set curLoop = 0
set sw = StopWatchCreate()
loop
exitwhen curLoop == ITERATIONS
if CONST_INT == 0 then
endif
set curLoop = curLoop + 1
endloop
set result[0] = StopWatchMark(sw)
call StopWatchDestroy(sw)
call BJDebugMsg("Constant: " + I2S(curLoop) +" iterations took " + R2S(result[0]))
call PolledWait(0.1)
// TEST 2
set curLoop = 0
set sw = StopWatchCreate()
loop
exitwhen curLoop == ITERATIONS
if Int == 0 then
endif
set curLoop = curLoop + 1
endloop
set result[1] = StopWatchMark(sw)
call StopWatchDestroy(sw)
call BJDebugMsg("Regular: " + I2S(curLoop) +" iterations took " + R2S(result[1]))
if (result[0] < result[1]) then
set result[2] = 100 - (result[0]/result[1] * 100)
call BJDebugMsg("Test #1 was " + I2S(R2I(result[2])) + "% faster than Test #2")
else
set result[2] = 100 - (result[1]/result[0] * 100)
call BJDebugMsg("Test #1 was " + I2S(R2I(result[2])) + "% slower than Test #2")
endif
call EnableTrigger(t)
endfunction
//===========================================================================
private function Init takes nothing returns nothing
call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(t, function Actions)
endfunction
endscope
I thought booleans only had 4 bits?
I thought booleans only had 4 bits?
Well, as i guessed, you have forgotten the matter of the variable length, use the same and test again.
That was tested long ago dude. I didn't forget the difference of a bit and a byte, as you were claiming we did.Also Mag is claiming that every 4th character adds additional overhead to speed