Quick Speed Fact

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
There ARE stopwatch natives, please look around before making assumptions. :O
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Before it, I can't get work with stopwatch in 1.21b, Warcraft does not load the map, anyway.
I tried before, but the map won't load, anyway.
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Make sure to import common.j as scripts\common.j or it doesn't work.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Lol, I just had a brilliant idea.
JASS:
globals
    integer array AA
    integer IA=0
    integer array AB
    integer IB=0
endglobals
function F1 takes nothing returns nothing
    set IA=IA+1
    set AA[IA]=1
endfunction
function F2 takes nothing returns nothing
    set IB=IB+1
    set AB[1]=IB
endfunction

If F1 is slower than F2, kudos to the person who figures out why (it is mentioned in my I2C tutorial). :cool:

Can someone test it for 4100 calls of each? :p

PS.
>Make sure to import common.j as scripts\common.j or it doesn't work.
I did try that, of course. :)
But I'll try the latest version some time.
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Also, make sure you use the NewGen Warcraft.

Edit: I might've did the test wrong, but here's my results.

Ok,

F1 - .374
F2 - .334

(Values multiplied by 100000)
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Yesh, It works for me now.

Result (1000 executions):
Hashtable : 0.04
Struct array : 0.025

JASS:
globals
    integer ii = GetRandomInt(-0x10000,0x10000)
endglobals

struct Data
    integer array lol[100]
endstruct

function Trig_Test_Actions takes nothing returns nothing
    local real result = 0
    local integer sw = StopWatchCreate()
    local integer i = 0
    
    loop
    exitwhen i == 1000
        set Data(i).lol[0] = ii
        set i = i + 1
    endloop
    
    set result = result + StopWatchMark(sw)
    call BJDebugMsg(R2S(result))
    call StopWatchDestroy(sw)
endfunction


JASS:
globals
    hashtable ht = InitHashtable()
    integer ii = GetRandomInt(-0x10000,0x10000)
endglobals

function Trig_Test_Actions takes nothing returns nothing
    local real result = 0
    local integer sw = StopWatchCreate()
    local integer i = 0
    
    loop
    exitwhen i == 1000
        call SaveInteger(ht,i,0,ii)
        set i = i + 1
    endloop
    
    set result = result + StopWatchMark(sw)
    call BJDebugMsg(R2S(result))
    call StopWatchDestroy(sw)
endfunction
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
LOL

25098330.jpg


1000 executions test.

JASS:
library Classic initializer Init

    globals
        private gamecache gc
        private hashtable ht
        private integer array Data
    endglobals
    
    function StoreStruct takes handle whichHandle, integer whichStruct returns nothing
        call StoreInteger(gc,I2S(GetHandleId(whichHandle)),"0",whichStruct)
    endfunction
    
    function GetStoredStruct takes handle whichHandle returns integer
        return GetStoredInteger(gc,I2S(GetHandleId(whichHandle)),"0")
    endfunction
    
    function SaveStruct takes handle whichHandle, integer whichStruct returns nothing
        call SaveInteger(ht,GetHandleId(whichHandle),0,whichStruct)
    endfunction
    
    function LoadStruct takes handle whichHandle returns integer
        return LoadInteger(ht,GetHandleId(whichHandle),0)
    endfunction
    
    function AttachStruct takes handle whichHandle, integer whichStruct returns nothing
        set Data[GetHandleId(whichHandle)-0x10000] = whichStruct
    endfunction
    
    function GetStruct takes handle whichHandle returns integer
        return Data[GetHandleId(whichHandle)-0x10000]
    endfunction
    
    private function Init takes nothing returns nothing
        call FlushGameCache(InitGameCache("=)"))
        set gc = InitGameCache("=)")
        set ht = InitHashtable()
    endfunction
    
endlibrary


Hashing formula in ABC v5.x is faster than v6.x after testing. =)
ABC v5.1 : 0.006
ABC v6.1 : 0.008
 

Jesus4Lyf

Good Idea™
Reaction score
397
Kingking, you should think about what you're doing more.
JASS:
    loop
    exitwhen i == 1000
        set Data(i).lol[0] = ii
        set i = i + 1
    endloop

This is terrible. How do you intend to write to the array slow of struct #1000 with a 100 member array? (Actually, I should check where the multiplication comes in.)

I'm not going to defend ABC because I believe that ABC is redundant due to hashtables (except for interface whatever you like). It should inline to hashtable use instead, I guess.

You still don't know how to benchmark. 1000 executions is nothing, and your data sets are not appropriate for how the systems are designed. You're a danger to your own integrity at the moment with the benchmark natives, and you need to be careful with your trigger happiness.

Point being you're gonna need to accept criticism, keep posting code with benchmarks so that people can see what's going on. :)
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I am a newbie on benchmark. :D.I need some learning.
Do you mind to give some education?:p
 

Jesus4Lyf

Good Idea™
Reaction score
397
With ABC you should make sure the things you attach to will not collide, because the system is made on the premise that they are most likely not to collide and it is a reasonable assumption.

You should generally run tests at least 10,000 times.

You should multiply the results by a bigger number - you should have more than one figure to judge the speed differences on (you're judging them on the final decimal place, which really amplifies the difference between them - "1.0" and "1.19" will read as a 10% difference).

Within each iteration of the loop, you should manually execute the line 10 times, not once (why everyone always does once is beyond me). The reason is that executing the "exitwhen" condition and the increment by one actually takes a small amount of processing power. You effectively divide that by 10 by running the statement 10 times.

Arrays go up to 8,191. "1000" times "100" is "100,000". Try with an array size of around 8. Also, multiply by 0 may have a different speed to multiplying by something else. Try array slot 5 or 6 or something. :)

My advice. :)
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Jesus4Lyf said:
Sounds correct to me. Anyone wanna guess why?
Is it a joke ?
It sounds pretty obvious for me, you use a constant in function 2 instead of a variable in function 1, for the index.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>It sounds pretty obvious for me, you use a constant in function 2 instead of a variable in function 1, for the index.
But I set to a constant in one, and set to a variable in the other.

The actual thing is apparently JASS arrays are not 8191 when the map starts. Cohadar said they extend every so often by copying themselves out to a new, larger memory location, when higher indexes are needed (see PUI thread).

I'm yet to thoroughly test whether or not it is true, though.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
//StopWatchCreate
//StopWatchMark
//StopWatchDestroy
library Tests initializer init

private struct Data[8]
    integer array omg [1001]
endstruct

globals
    private hashtable ht = InitHashtable()
    private timer T = CreateTimer()
    private real T0 = 0
    private real T1 = 0
endglobals

private function Actions takes nothing returns nothing
    local integer i = 0
    local real t1
    local real t0
    local integer sw = StopWatchCreate()
    
    set t0 = StopWatchMark(sw)
    loop
    exitwhen i>=1000
        set Data(1).omg<i> = i
        set Data(2).omg<i> = i
        set Data(3).omg<i> = i
        set Data(4).omg<i> = i
        set Data(5).omg<i> = i
        set Data(6).omg<i> = i
        set Data(7).omg<i> = i
        set Data(8).omg<i> = i
        set Data(1).omg<i> = i
        set Data(2).omg<i> = i
        set i = i + 1
    endloop
    set t1 = StopWatchMark(sw)
    set T0 = 100000000 * (t1-t0)
    
    call TriggerSleepAction(.0)
    
    set i = 0
    set t0 = StopWatchMark(sw)
    loop
    exitwhen i&gt;=1000
        call SaveInteger(ht,1,i,i)
        call SaveInteger(ht,2,i,i)
        call SaveInteger(ht,3,i,i)
        call SaveInteger(ht,4,i,i)
        call SaveInteger(ht,5,i,i)
        call SaveInteger(ht,6,i,i)
        call SaveInteger(ht,7,i,i)
        call SaveInteger(ht,8,i,i)
        call SaveInteger(ht,1,i,i)
        call SaveInteger(ht,2,i,i)
        set i = i + 1
    endloop
    set t1 = StopWatchMark(sw)
    set T1 = 100000000 * (t1-t0)
    
    call StopWatchDestroy(sw)
    call BJDebugMsg(&quot;Struct array speed : &quot; + R2S(T0) + &quot;  | Hashtable speed : &quot; + R2S(T1))
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(trig,Player(0),&quot;set&quot;,true)
    call TriggerAddAction(trig,function Actions)
endfunction

endlibrary

</i></i></i></i></i></i></i></i></i></i>


62050807.jpg

:confused:
Am I doing it wrong?:nuts:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top