Calling a function

Status
Not open for further replies.
Level 6
Joined
Jun 19, 2010
Messages
143
Hi guys, I'd like to kno what is more OP. For example
I have 2 functions: 1 is Hinit and the other is afplayer
So if I do (see the bold text)

function main takes nothing returns nothing
.....
call ExecuteFunc("Hinit")
call afplayer()

endfunction

which one is faster, more efficient and optimized. Thanks,
 
With a simple setup like this:
JASS:
function runthis takes nothing returns nothing
    
endfunction

function act1 takes nothing returns nothing
    local integer i = 0
    local integer sw
    set sw = StopWatchCreate()
    loop
        exitwhen (i == 1000)
        
        call ExecuteFunc("runthis")
        
        set i = i + 1
    endloop
    call StopWatchMark(sw)
    call StopWatchDestroy(sw)
endfunction

function act2 takes nothing returns nothing
    local integer i = 0
    local integer sw
    set sw = StopWatchCreate()
    loop
        exitwhen (i == 1000)
        
        call runthis()
        
        set i = i + 1
    endloop
    call StopWatchMark(sw)
    call StopWatchDestroy(sw)
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_006 takes nothing returns nothing
    local trigger t
    set t = CreateTrigger(  )
    call TriggerAddAction( t, function act1 )
    call TriggerRegisterPlayerChatEvent( t, Player(0), "checkspeed1", true )
    set t = CreateTrigger(  )
    call TriggerAddAction( t, function act2 )
    call TriggerRegisterPlayerChatEvent( t, Player(0), "checkspeed2", true )
endfunction

The ExecuteFunc loop takes about .009 seconds whereas the normal runthis() call takes about .0007 seconds. With that sort of time, a normal function call is more than ten times faster.

Keep in mind these numbers are for running a function 1000 times inside of a loop. Which you pick for a function call that occurs once is basically insignificant.
 
Its not only a difference of performance. With normal function calls you can pass arguments and take returned values, that doesnt work with ExecuteFunc. But ExecuteFunc starts the function in a new thread which helps if you have problems with the op limit (but there are other ways to do that, like nulltimer or ForGroup ...
ExecuteFunc is rarely used, anyway in rare situations calling functions via Strings (the functions name) can be quite useful.
 
Thats wrong, you cannot use ExecuteFunc in GUI. You are mixing this up with TriggerExecute, which is used in GUI as a replacement for function calls, but its two completely different things.
  • Events
    • Timer - Elapsed Game Time 0
  • Conditions
  • Actions
    • Custom script: call ExecuteFunc("haha")
    • Custom script: endfunction
    • Custom script: function haha takes nothing returns nothing
    • Game - Display text message "wrong!"
 
Status
Not open for further replies.
Back
Top