• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

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