• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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,
 
Level 5
Joined
Jun 16, 2004
Messages
108
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.
 
Level 5
Joined
Jun 16, 2004
Messages
108
checkspeed1 runs act1, and checkspeed2 runs act2.

I was using the StopWatch plugin for a tool of mine http://www.wc3c.net/showthread.php?t=109232
There is a certain amount of overhead that is introduced to function calls with the tool though, so the times might be off by something like .000020 in my case above.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
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.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
than castle fight uses GUI because u cant call functions in gui only execute..
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
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.
Top