• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Timer vs loop< about speed view

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
Question is the different in speed is noticeable between i use for a buff a timer and a periodic trigger or in same trigger i use loop/wait 1 sec for check allways the buffed units hp?

so i talk about this:
JASS:
function Trig_Aoe_Amplify_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

function Trig_Aoe_Amplify_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit pu
    local unit array ua
    local integer bdur = 15
    local integer a = 0
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local group gr = CreateGroup()
    local string s = "Abilities\\Spells\\NightElf\\BattleRoar\\RoarCaster.mdl"
    local string s1 = "Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeDamageTarget.mdl"
    local effect f = AddSpecialEffectTarget(s, u, "overhead")
    local effect array df
    local player p = GetOwningPlayer(u)
    local integer i = 0
    local integer d

    call GroupEnumUnitsInRange(gr, x, y, 250.00, null)
    loop
        set pu = FirstOfGroup(gr)
        exitwhen (pu==null)
        if ((IsUnitEnemy(pu, GetTriggerPlayer())) and (GetUnitState(pu, ConvertUnitState(0)) > 0)) then
            set df[i] = AddSpecialEffectTarget(s1, pu, "overhead")
            set ua[i] = pu
            set i = i + 1
        endif
        call GroupRemoveUnit(gr, pu)
    endloop
    call DestroyEffect(f)
//looping part
    set d = i
    loop
        exitwhen (a==bdur)
        call TriggerSleepAction(1)
        loop
            exitwhen (i==d)
            if GetUnitState(ua[i], ConvertUnitState(0))<=0 then
                call DestroyEffect(df[i])
                set df[i] = null
                set ua[i] = null
            endif
            set i = i + 1
        endloop
        set i = 0
        set a = a + 1
    endloop
//loop end
    loop
        exitwhen (i==d)
        if (ua[i]!=null) then
            call DestroyEffect(df[i])
            set df[i] = null
            set ua[i] = null
        endif
        set i = i + 1
    endloop

    call DestroyGroup(gr)
    set f = null
    set s = null
    set u = null
    set gr = null
    set p = null
    set s1 = null
endfunction

//===========================================================================
function InitTrig_Aoe_amplify_damage takes nothing returns nothing
    set gg_trg_Aoe_amplify_damage = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Aoe_amplify_damage, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Aoe_amplify_damage, Condition( function Trig_Aoe_Amplify_Conditions ) )
    call TriggerAddAction( gg_trg_Aoe_amplify_damage, function Trig_Aoe_Amplify_Actions )
endfunction
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Timer has a much larger resolution than TriggerSleepAction. TriggerSleepAction is limited to 0.1 seconds + delay based on ping (so is slower in multiplayer than singleplayer). Timers can go smaller than 0.001 seconds with realitive accuracy (although they do exhibit inaccuracy at that time such as running 1001 times every second).
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Timer has a much larger resolution than TriggerSleepAction. TriggerSleepAction is limited to 0.1 seconds + delay based on ping (so is slower in multiplayer than singleplayer). Timers can go smaller than 0.001 seconds with realitive accuracy (although they do exhibit inaccuracy at that time such as running 1001 times every second).

ok so timer is more accurated but in background timer must keep the calculation very often, better if triggers where need fast reaction but if i dont need that short delay, so ~1sec/0.5 sec with triggersleep loop is faster than timer (faster => need less cpu usage coz less calculation?)?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
ok so timer is more accurated but in background timer must keep the calculation very often, better if triggers where need fast reaction but if i dont need that short delay, so ~1sec/0.5 sec with triggersleep loop is faster than timer (faster => need less cpu usage coz less calculation?)?
They should both be relying on the OS kernal to do the time based schedualling so I do not see any possible difference between the 2 as far as background load goes. Obviously faster timeouts will run more often so will use more time executing but the background load for both methods should be the same if the timeout is the same.
 
Status
Not open for further replies.
Top