- Joined
- Jun 23, 2007
- Messages
- 4,066
Here's a test map showing how to accurately benchmark things, it may be useful or interesting to some who didn't already know about the StopWatch natives.
The attached map also includes other tests such as UnitAlive vs GetWidgetLife, TriggerExecute vs TriggerEvaluate, and some operator comparisons.
It requires RtC and patch 1.24.
The attached map also includes other tests such as UnitAlive vs GetWidgetLife, TriggerExecute vs TriggerEvaluate, and some operator comparisons.
It requires RtC and patch 1.24.
JASS:
scope BenchmarkTemplate initializer Init
globals
private constant integer ITERATIONS = 8190
private trigger t = CreateTrigger()
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
// YOUR CODE HERE
set curLoop = curLoop + 1
endloop
set result[0] = StopWatchMark(sw)
call StopWatchDestroy(sw)
//===========================================================================
call BJDebugMsg("Test #1: " + I2S(curLoop) +" iterations took " + R2S(result[0]))
call PolledWait(0.1)
// TEST 2
//===========================================================================
set curLoop = 0
set sw = StopWatchCreate()
loop
exitwhen curLoop == ITERATIONS
// YOUR CODE HERE
set curLoop = curLoop + 1
endloop
set result[1] = StopWatchMark(sw)
call StopWatchDestroy(sw)
//===========================================================================
call BJDebugMsg("Test #2: " + 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