• 🏆 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] A weird Benchmark Result.

Status
Not open for further replies.
Hey everyone, today I was testing the benchmarking of different functions. I tried H2I, Pow among others. Something that left me shocked was when I benchmarked Sine vs DoNothing. Vexorian had proved that natives are a lot more faster than jass functions by comparing DoNothing with Cosine. I tried doing that test once more, but with sine, and the result was that DoNothing > Sine. Here's the code:

JASS:
function Trig_Benchmark_Actions takes nothing returns nothing
local integer i = 0
local real r
local real g
//local player p = Player(0)
//local integer f = H2I(p)
local integer s = StopWatchCreate()
loop
    exitwhen i >= 5000
    call DoNothing()
    set i = i + 1
endloop
set g = StopWatchMark(s)
set i = 0
call StopWatchDestroy(s)
set s = StopWatchCreate()
loop
    exitwhen i >= 5000
    call Sin(2.) //i'm not assigning it to any value, in order for it to be faster
    set i = i + 1
endloop
set r = StopWatchMark(s)
call StopWatchDestroy(s)
//call BJDebugMsg(R2S(g))
call BJDebugMsg(R2SW(g,10,10))
call BJDebugMsg(R2SW(r,10,10))
endfunction

//===========================================================================
function InitTrig_Benchmark takes nothing returns nothing
    set gg_trg_Benchmark = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Benchmark, function Trig_Benchmark_Actions )
endfunction

The results were: 0.006597519 seconds for DoNothing
0.007065160 seconds for Sine.

The thing is that Vexorian proved Cosine to be 3 times faster than DoNothing alone, but now I ask myself which mistake I made or if my test is right.

I also did another test.
JASS:
function Useless takes real r returns nothing
endfunction

function Trig_Benchmark_Actions takes nothing returns nothing
local integer i = 0
local real r
local real g
//local player p = Player(0)
//local integer f = H2I(p)
local integer s = StopWatchCreate()
loop
    exitwhen i >= 5000
    call Useless(2.)
    set i = i + 1
endloop
set g = StopWatchMark(s)
set i = 0
call StopWatchDestroy(s)
set s = StopWatchCreate()
loop
    exitwhen i >= 5000
    call Sin(2.)
    set i = i + 1
endloop
set r = StopWatchMark(s)
call StopWatchDestroy(s)
//call BJDebugMsg(R2S(g))
call BJDebugMsg(R2SW(g,10,10))
call BJDebugMsg(R2SW(r,10,10))
endfunction

//===========================================================================
function InitTrig_Benchmark takes nothing returns nothing
    set gg_trg_Benchmark = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Benchmark, function Trig_Benchmark_Actions )
endfunction

in this one Sine > Useless. The reasons may be 2: first Useless now takes an argument, which slows it down, and second, Useless is away from the top, thus it's slower than the rest.

Results
Useless: 0.0085
Sine: 0.0073
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
I use StoppWatchMark() a bit different:
globals
integer S=StopWatchCreate()
endglobals

function...
local real e
local real s=StopWatchMark(S)
...code
set e=StopWatchMark(S)

s-e=result

Maybe this is the error~
But i dont hink so :/
I had alot bugs in the past with stopwatches; if i used the in a term (set e=s-StopWatchMark(S)) i always got 0 ..
 
I use StoppWatchMark() a bit different:
globals
integer S=StopWatchCreate()
endglobals

function...
local real e
local real s=StopWatchMark(S)
...code
set e=StopWatchMark(S)

s-e=result

Maybe this is the error~
But i dont hink so :/
I had alot bugs in the past with stopwatches; if i used the in a term (set e=s-StopWatchMark(S)) i always got 0 ..

yeah, resting reals that are so low, normally brings some errors.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I dunno if it does matter or not.
But you create a StopWatch in a local declaration and after you set his variable.
I would say, be sure, always set the local.

JASS:
function Trig_Benchmark_Actions takes nothing returns nothing
local integer i = 0
local real r
local real g
//local player p = Player(0)
//local integer f = H2I(p)
local integer s = 0
set s = StopWatchCreate()
loop
    exitwhen i >= 5000
    call DoNothing()
    set i = i + 1
endloop
set g = StopWatchMark(s)
set i = 0
call StopWatchDestroy(s)
set s = StopWatchCreate()
loop
exitwhen i >= 5000
    call Sin(2.) //i'm not assigning it to any value, in order for it to be faster
    set i = i + 1
endloop
set r = StopWatchMark(s)
call StopWatchDestroy(s)
//call BJDebugMsg(R2S(g))
call BJDebugMsg(R2SW(g,10,10))
call BJDebugMsg(R2SW(r,10,10))
endfunction

//===========================================================================
function InitTrig_Benchmark takes nothing returns nothing
    set gg_trg_Benchmark = CreateTrigger( )
    call TriggerAddAction( gg_trg_Benchmark, function Trig_Benchmark_Actions )
endfunction
 
Status
Not open for further replies.
Top