Bribe
vJass errors are legion
- Reaction score
- 67
Comparison:
Approximate Results & Conclusions:
Comments & Personal Criticism:
Code:
[LJASS]UnitAlive[/LJASS] vs [LJASS]UNIT_TYPE_DEAD[/LJASS]
Approximate Results & Conclusions:
- Tested on latest Warcraft III Version.
- [LJASS]UnitAlive[/LJASS] is 50% faster than [LJASS]UNIT_TYPE_DEAD[/LJASS].
Comments & Personal Criticism:
- Nestharus thought UnitAlive was a wrapper for UNIT_TYPE_DEAD, this strongly differs.
Code:
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
native UnitAlive takes unit id returns boolean
/////////////////////////
// Benchmarking script //
/////////////////////////
// Initialisation
globals
// ...
unit u
endglobals
////////////
private function Init takes nothing returns nothing
// things required to be performed once before your test
set u = CreateUnit(Player(0), 039;hfoo039;, 0,0,0)
endfunction
// Tests
globals
private constant string TITLE_A="UnitAlive"
//! textmacro Benchmark__TestA
call UnitAlive(u)
call UnitAlive(u)
call UnitAlive(u)
call UnitAlive(u)
call UnitAlive(u)
call UnitAlive(u)
call UnitAlive(u)
call UnitAlive(u)
call UnitAlive(u)
call UnitAlive(u)
//! endtextmacro
private constant string TITLE_B="IsUnitType"
//! textmacro Benchmark__TestB
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
call IsUnitType(u, UNIT_TYPE_DEAD)
//! 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 = StopWatchCreate()
local integer i = 0
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