• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

GetTriggerWidget(), GetTriggerUnit()

Status
Not open for further replies.
You could always typecast:
JASS:
globals
    hashtable blah = InitHashtable()
endglobals
function W2U takes widget w returns unit
    call SaveWidgetHandle(blah,0,0,w)
    return LoadUnitHandle(blah,0,0)
endfunction

But that'd obviously be less efficient. =P

EDIT: Ok, I ran some benchmarks:
attachment.php


I've done it several times (more than shown below), and each time GetTriggerUnit() returned faster.

In the image, I show 8 trials, here is the speed comparison for GetTriggerUnit() to GetTriggerWidget():
  • Trial 1: 1.4851% faster
  • Trial 2: 5.2632% faster
  • Trial 3: 0.5405% faster
  • Trial 4: 23.519% faster
  • Trial 5: 4.5714% faster
  • Trial 6: 5.7618% faster
  • Trial 7: 0.1841% faster
  • Trial 8: 3.8847% faster

Test was done on a blank map using NewGen Editor along with the Stopwatch Natives.
Tested in version 1.24.4.6387 (latest version)
JASS:
library Benchmark initializer OnInit
    native StopWatchCreate  takes nothing returns integer
    native StopWatchMark    takes integer stopwatch returns real
    native StopWatchDestroy takes integer stopwatch returns nothing
    globals
    private constant string TITLE_A="GetTriggerUnit()       "
    //! textmacro Benchmark__TestA
        call GetTriggerUnit()
    //! endtextmacro
    private constant string TITLE_B="GetTriggerWidget() "
    //! textmacro Benchmark__TestB
        call GetTriggerWidget()
    //! endtextmacro
    endglobals
    private function TestA1000 takes nothing returns nothing
        local integer i=100
        loop
            exitwhen i==0
            set i=i-1
            //! runtextmacro Benchmark__TestA() // 1
            //! runtextmacro Benchmark__TestA() // 2
            //! runtextmacro Benchmark__TestA() // 3
            //! runtextmacro Benchmark__TestA() // 4
            //! runtextmacro Benchmark__TestA() // 5
            //! runtextmacro Benchmark__TestA() // 6
            //! runtextmacro Benchmark__TestA() // 7
            //! runtextmacro Benchmark__TestA() // 8
            //! runtextmacro Benchmark__TestA() // 9
            //! runtextmacro Benchmark__TestA() // 10
        endloop
    endfunction
    private function TestB1000 takes nothing returns nothing
        local integer i=100
        loop
            exitwhen i==0
            set i=i-1
            //! runtextmacro Benchmark__TestB() // 1
            //! runtextmacro Benchmark__TestB() // 2
            //! runtextmacro Benchmark__TestB() // 3
            //! runtextmacro Benchmark__TestB() // 4
            //! runtextmacro Benchmark__TestB() // 5
            //! runtextmacro Benchmark__TestB() // 6
            //! runtextmacro Benchmark__TestB() // 7
            //! runtextmacro Benchmark__TestB() // 8
            //! runtextmacro Benchmark__TestB() // 9
            //! runtextmacro Benchmark__TestB() // 10
        endloop
    endfunction
    
    private function OnEsc takes nothing returns nothing
        local integer sw
        local integer i
        set i=0
        set sw=StopWatchCreate()
        loop
            set i=i+1
            call TestA1000.evaluate()
            exitwhen i==10
        endloop
        call BJDebugMsg("|cff66ddff"+TITLE_A+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
        set i=0
        set sw=StopWatchCreate()
        loop
            set i=i+1
            call TestB1000.evaluate()
            exitwhen i==10
        endloop
        call BJDebugMsg("|cffddff66"+TITLE_B+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
    endfunction
    private function OnInit takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterPlayerEvent(t,Player(0),EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(t,function OnEsc)
    endfunction
endlibrary
 

Attachments

  • BenchGetTrig.jpg
    BenchGetTrig.jpg
    158.4 KB · Views: 267
Last edited:
Status
Not open for further replies.
Top