| 12-10-2009, 12:56 AM | #1 |
Zinc:
///////////////////////////////////////////////
// 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
//! textmacro TestPattern takes code
TriggerSleepAction(0);
BJDebugMsg("$code$");
sw = StopWatchCreate();
for(i = 0; i < 1000; i+=1)
{
$code$
$code$
$code$
$code$
$code$
$code$
$code$
$code$
$code$
$code$
}
res= StopWatchMark(sw);
StopWatchDestroy(sw);
BJDebugMsg(R2S(res*1000));
//! endtextmacro
//! zinc
library CollectionTest
{
hashtable table = InitHashtable();
public function Trig_CollectionTest_Actions()
{
integer i;
integer sw;
real res;
integer num;
//! runtextmacro TestPattern("/* exists miss */HaveSavedInteger(table,0,1);")
//! runtextmacro TestPattern("/* Get Miss */ LoadInteger(table,0,1);")
//! runtextmacro TestPattern("/* set */SaveInteger(table,0,2,2);")
//! runtextmacro TestPattern("/* Get hit */ LoadInteger(table,0,2);")
//! runtextmacro TestPattern("/* exists hit */ HaveSavedInteger(table,0,2);")
//! runtextmacro TestPattern("/* flush */ RemoveSavedInteger(table,0,2);")
}
}
//! endzinc
//===========================================================================
function InitTrig_CollectionTest takes nothing returns nothing
set gg_trg_CollectionTest = CreateTrigger( )
call TriggerRegisterPlayerEventEndCinematic( gg_trg_CollectionTest, Player(0) )
call TriggerAddAction( gg_trg_CollectionTest, function Trig_CollectionTest_Actions )
endfunction
The means of testing was trying each method 10 times in an iterative loop of 1000 tries. This was to lower the time wasted on simply setting i= i+1. After each test the stopwatch was destroyed and a sleep was used to clense the pop limit. Each of these results were multiplied by 1000 to make them large enough to notice a difference. Test + numbers::
I didn't assign to variables or test or anything like that to be fair, as if statements in jass seem to be lightening fast, whereas setting is slower. |
| 12-10-2009, 06:01 AM | #2 |
what about gamecache and arrays? can you perform same test with cache and arrays, may be using cache will be faster then hashtable |
| 12-12-2009, 04:40 AM | #3 |
I've performed some benchmarks in the JH thread, but the general thing is that array < hashtable < gamecache by an order of 1 each. So GC is about 3x slower then array, and ht is about 2x slower then array. Of course GC tends to be real slower, as you often use I2S and strings are slower. |
| 12-12-2009, 09:33 AM | #4 |
soo keep structs and struct handle via hash is best way? |
