Strange behavior when benchmarking

jwallstone

New Member
Reaction score
33
I'm trying to figure out how fast various ways of using hashtables are compared to globals, and wrote this simple benchmarking script. However, depending on the number of iterations in each loop, the code only reaches a certain section. As N increases, the script stops at an earlier and earlier section. Does anyone know why this is? Is there some limitation on the number of function calls allowed in a script?

I'ved attached the map for anyone who wants to try it out, but here's the code:

JASS:

function testmap takes nothing returns nothing
    local hashtable table = InitHashtable()
    local real t1
    local real t2
    local integer N = 3000
    local integer counter = 0
    local integer i1 = StringHash("Index1")
    local integer i2 = StringHash("Index2")
    local unit u = CreateUnit(Player(0),'ewsp',0.0,0.0,270.0)
    
    call PolledWait(2.0)
    
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time1 = " + R2S(t2-t1))
    
    set counter = 0
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        call SaveAgentHandle(table, i1, i2, u)
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time2 = " + R2S(t2-t1))
    
    set counter = 0
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        set u = LoadUnitHandle(table, i1, i2)
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time3 = " + R2S(t2-t1))
    
    set counter = 0
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        set udg_temp = u
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time4 = " + R2S(t2-t1))
    
    set counter = 0
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        set u = udg_temp
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time5 = " + R2S(t2-t1))
    
    set counter = 0
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        call SaveAgentHandle(table, StringHash("Index1"), StringHash("Index2"), u)
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time6 = " + R2S(t2-t1))
    
    set counter = 0
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        set u = LoadUnitHandle(table, StringHash("Index1"), StringHash("Index2"))
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time7 = " + R2S(t2-t1))
    
    set counter = 0
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        call SaveAgentHandle(table, GetHandleId(u), StringHash("Index2"), u)
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time8 = " + R2S(t2-t1))
    
    set counter = 0
    set t1 = TimerGetElapsed(bj_gameStartedTimer)
    loop
        exitwhen (counter >= N)
        set u = LoadUnitHandle(table, GetHandleId(u), StringHash("Index2"))
        set counter = counter + 1
    endloop
    set t2 = TimerGetElapsed(bj_gameStartedTimer)
    call BJDebugMsg("Time9 = " + R2S(t2-t1))
endfunction
 

Attachments

  • Testmap.w3x
    12.7 KB · Views: 104

uberfoop

~=Admiral Stukov=~
Reaction score
177
There is a limit to the amount of operations that can be executed in a single thread.


In general, you can avoid this limitation by going to a new thread by indirectly calling functions, for example via ExecuteFunc, or by sticking a small wait in the middle of the code.

Anyway, that's probably what's affecting your script, given that you're sticking thousands of calls within many loops.
 

jwallstone

New Member
Reaction score
33
That explains it. Thanks for your help. I'll add in small waits.

What do mean by stopwatch natives? What are they called?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top