Troll-Brain
You can change this now in User CP.
- Reaction score
- 85
Comparison:
Approximate Results & Conclusions:
Comments & Personal Criticism:
Ofc fatally isUnitInList will become faster with more units, but in an other hand i don't see why someone would need a such huge UnitList (if we forgot about ghost units).
Also only 56.4% slower is pretty good.
Code:
[LJASS]IsUnitInGroup[/LJASS] vs [LJASS]isUnitInList[/LJASS]
Approximate Results & Conclusions:
- Tested on Warcraft III Version 1.24.3.6384
- [LJASS]IsUnitInGroup[/LJASS] is 56.4 % faster than [LJASS]isUnitInList with 10 units[/LJASS]
- [lJASS]IsUnitInGroup[/lJASS] : 65.830 ; UnitList.addUnit : 102.956
- [LJASS]IsUnitInGroup[/LJASS] is 50 % faster than [LJASS]isUnitInList with 30 units[/LJASS]
- [lJASS]IsUnitInGroup[/lJASS] : 202.172 ; UnitList.addUnit : 302.784
Comments & Personal Criticism:
Ofc fatally isUnitInList will become faster with more units, but in an other hand i don't see why someone would need a such huge UnitList (if we forgot about ghost units).
Also only 56.4% slower is pretty good.
Code:
JASS:
library Benchmark initializer OnInit requires UnitList
///////////////////////////////////////////////
// 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
private unit array U
private group Grp
private UnitList UnL
private UnitList X
private integer Index = 0
private constant integer UNIT_NUMBER = 100
endglobals
private function Init takes nothing returns nothing
local integer i = 0
set Grp = CreateGroup()
set UnL = UnitList.create()
loop
exitwhen i == UNIT_NUMBER
set U<i> = CreateUnit(Player(0),039;hfoo039;,0.,0.,0.)
call GroupAddUnit(Grp,U<i>)
call UnL.addUnit(U<i>)
set i = i+1
endloop
call BJDebugMsg("init done")
endfunction
// Tests
globals
private constant string TITLE_A="IsUnitInGroup"
//! textmacro Benchmark__TestA
set Index = 0
loop
exitwhen Index == UNIT_NUMBER
if IsUnitInGroup(U[Index],Grp) then // 1
endif
if IsUnitInGroup(U[Index],Grp) then // 2
endif
if IsUnitInGroup(U[Index],Grp) then // 3
endif
if IsUnitInGroup(U[Index],Grp) then // 4
endif
if IsUnitInGroup(U[Index],Grp) then // 5
endif
set Index = Index+1
endloop
//! endtextmacro
private constant string TITLE_B="isUnitInList"
//! textmacro Benchmark__TestB
set Index = 0
loop
exitwhen Index == UNIT_NUMBER
if UnL.isUnitInList(U[Index]) then // 1
endif
if UnL.isUnitInList(U[Index]) then // 2
endif
if UnL.isUnitInList(U[Index]) then // 3
endif
if UnL.isUnitInList(U[Index]) then // 4
endif
if UnL.isUnitInList(U[Index]) then // 5
endif
set Index = Index+1
endloop
//! endtextmacro
endglobals
// execution
private function TestA1000 takes nothing returns nothing
local integer i=10
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
//call BJDebugMsg("Test A performed")
endfunction
private function TestB1000 takes nothing returns nothing
local integer i=10
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
//call BJDebugMsg("Test B performed")
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 == 100
endloop
call BJDebugMsg(TITLE_A+": "+R2S(StopWatchMark(sw)*100))
call StopWatchDestroy(sw)
set i=0
set sw=StopWatchCreate()
loop
set i=i+1
call TestB1000.evaluate()
exitwhen i == 100
endloop
call BJDebugMsg(TITLE_B+": "+R2S(StopWatchMark(sw)*100))
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</i></i></i>