Бенчмарки - Форум


Правила форума ·

  • Страница 1 из 1
  • 1
Форум » Warcraft III » Триггеры и Jass » Бенчмарки (Смотрим другие, показываем свои!)
Бенчмарки

[DUОS]

#1
Бенчмарки - тесты на производительность какой-либо функции или конструкции.

1. if then endif vs if then else endif
[jass]function Test1 takes nothing returns nothing
local integer i = 0

loop
set i = i + 1
if not false then
call BJDebugMsg(I2S(i))
endif
endloop

//809
endfunction

function Test2 takes nothing returns nothing
local integer i = 0

loop
set i = i + 1
if false then
else
call BJDebugMsg(I2S(i))
endif
endloop

//811
endfunction

function Test3 takes nothing returns nothing
local integer i = 0

loop
set i = i + 1
if false == false then
call BJDebugMsg(I2S(i))
endif
endloop

//803
endfunction[/jass]

Обычное сравнение if false == false then оказалось самым медленным! Чуть быстрее not, а уж совсем быстро отрицать условие в блоке else. Делайте выводы! smile

2. GetUnitState(whichUnit,UNIT_STATE_LIFE) vs GetWidgetLife(whichUnit)

[jass]function Test1 takes nothing returns nothing
       local integer i = 0
       local unit u = CreateUnit(Player(0),'hfoo',0.,0.,0.)
          
       loop
           set i = i + 1
           call GetUnitState(u,UNIT_STATE_LIFE)
           call BJDebugMsg(I2S(i))
       endloop
          
       set u = null
       //807
endfunction

function Test2 takes nothing returns nothing
       local integer i = 0
       local unit u = CreateUnit(Player(0),'hfoo',0.,0.,0.)
          
       loop
           set i = i + 1
           call GetWidgetLife(u)
           call BJDebugMsg(I2S(i))
       endloop
          
       set u = null
       //811
endfunction[/jass]

GetWidgetLife быстрее. Я задолбался уже это доказывать.

3. GetWidgetLife(whichUnit) > 0. vs IsUnitType(whichUnit,UNIT_TYPE_DEAD)

[jass]function Test1 takes nothing returns nothing
      local integer i = 0
      local unit u = CreateUnit(Player(0),'hfoo',0.,0.,0.)
        
      loop
          set i = i + 1
          if GetWidgetLife(u,UNIT_STATE_LIFE) > 0. then
              call BJDebugMsg(I2S(i))
          endif
      endloop
        
      set u = null
      //798
endfunction

function Test2 takes nothing returns nothing
      local integer i = 0
      local unit u = CreateUnit(Player(0),'hfoo',0.,0.,0.)
        
      loop
          set i = i + 1
          if IsUnitType(u,UNIT_TYPE_DEAD) then
          else
              call BJDebugMsg(I2S(i))
          endif
      endloop
        
      set u = null
      //802
endfunction[/jass]

Быстрее оказалась проверка типа боевой единицы. Вот это да.
Сообщение отредактировал [DUOS] - Пт, 19.04.13, 12:48
Школа - это место, где шлифуют булыжники и портят алмазы. © Роберт Ингерсолл
Форум » Warcraft III » Триггеры и Jass » Бенчмарки (Смотрим другие, показываем свои!)
  • Страница 1 из 1
  • 1
Поиск: