Which is faster?

NoobImbaPro

You can change this now in User CP.
Reaction score
60
I've got two codes that do the same thing, which is faster and why?
JASS:
method iterate takes code func returns nothing
    local trigger temp = CreateTrigger()
    local thistype cnt = this.guard
 
    call TriggerAddAction(temp, func)
 
    loop
        set cnt = cnt.next
    exitwhen cnt == cnt.guard
        set enumerable = cnt
        call TriggerExecute(temp)
    endloop
 
    call DestroyTrigger(temp)
    set temp = null
endmethod


JASS:
method iterate takes string funcname returns nothing
    local thistype cnt = this.guard
 
    loop
        set cnt = cnt.next
    exitwhen cnt == cnt.guard
        set enumerable = cnt
        call ExecuteFunc( funcname )
    endloop
 
endmethod
 

Nestharus

o-o
Reaction score
84
They both suck :\

JASS:
List list = List.create()
local integer sentinel = list
//populate
 
loop
    set list = list.next
    exitwhen list == sentinel
 
    //code
endloop
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
The second one is faster (according to old benchmarks), but some people stray away from it. There isn't really anything wrong with ExecuteFunc any more iirc (optimizer doesn't break it, and it doesn't crash when an invalid func is put in)

However, triggers are usually failsafe. If the function does not exist, it will throw an error. For ExecuteFunc, it just won't work. That's why some may prefer to use triggers. However, dynamic triggers (creating and destroying) are usually unnecessary. For example, if you just need to start a new thread or w/e, you can simply save the triggeraction to a local, execute the trigger, and then TriggerRemoveAction. Just use one global trigger, that way you don't need to destroy it.

I think some people said that TriggerEvaluate also runs on a new thread, but I can't confirm that. However, it may be something worth trying since TriggerEval is faster. (again, according to old benchmarks. Some things might've changed since)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top