• 🏆 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!

[JASS] Is SaveAgentHandle the fastest?

Status
Not open for further replies.
Level 12
Joined
Apr 15, 2008
Messages
1,063
Propably the same as AgentHandle, I think the difference is caused by changing the variable type from unit to agent, unit to handle will be the same.
My point, however, was that it is virtually no difference.

EDIT: After further tests, the difference between these functions seem to be even lower, they are all equally fast
 
Save Unit handle is faster. However, I didn't get quite as low a difference as Mort's results. I seemed to get roughly 7-10% faster for SaveUnitHandle opposed to SaveAgentHandle, and roughly the same speed difference for SaveWidgetHandle:
JASS:
library Benchmark initializer OnInit
    ///////////////////////////////////////////////
    // Native declarations for stopwatch natives //
    //  - Requires no modified common.j import   //
    ///////////////////////////////////////////////
    native StopWatchCreate  takes nothing returns integer
    native StopWatchMark    takes integer stopwatch returns real
    native StopWatchDestroy takes integer stopwatch returns nothing
    
    /////////////////////////
    // Benchmarking script //
    /////////////////////////
    
    // Initialisation
    globals
        // ...
        hashtable h = InitHashtable()
        unit g
    endglobals
    
    private function Init takes nothing returns nothing
        set g = CreateUnit(Player(0),'hfoo',1000,1000,0)
        // things required to be performed once before your test
    endfunction
    
    // Tests
    globals
    private constant string TITLE_A="SaveWidgetHandle"
    //! textmacro Benchmark__TestA
        call SaveWidgetHandle(h,0,0,g)
        call SaveWidgetHandle(h,0,0,g)    
        call SaveWidgetHandle(h,0,0,g)
        call SaveWidgetHandle(h,0,0,g)
        call SaveWidgetHandle(h,0,0,g)
        call SaveWidgetHandle(h,0,0,g)
        call SaveWidgetHandle(h,0,0,g)
        call SaveWidgetHandle(h,0,0,g)
        call SaveWidgetHandle(h,0,0,g)
        call SaveWidgetHandle(h,0,0,g)
    //! endtextmacro
    private constant string TITLE_B="SaveUnitHandle"
    //! textmacro Benchmark__TestB
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
        call SaveUnitHandle(h,0,0,g)
    //! endtextmacro
    endglobals
    
    // execution
    private function TestA1000 takes nothing returns nothing
        local integer i=100 // hence 1,000 execs
        loop
            exitwhen i==0
            set i=i-1
            // Repeat x10
            //! 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 // hence 1,000 execs
            set i=i-1
            // Repeat x10
            //! 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() // x10 - 10,000 executions altogether.
            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() // x10 - 10,000 executions altogether.
            exitwhen i==10
        endloop
        call BJDebugMsg("|cffddff66"+TITLE_B+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
    endfunction
    
    ///////////////////////////////
    // Registers the OnEsc event //
    ///////////////////////////////
    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)
        call Init()
    endfunction
endlibrary

That is what I used.
 
Status
Not open for further replies.
Top