so to say , how you choose to use which data manipulation function , array or list or map ?
for gamer you may think array is the best for speed ,
but have you ever think about to test and compare purebasic array , list and map before ?
here is the test :
Code: Select all
; ===========================
; Benchmark and Perfomance Test for PureBasic internal library function
; MAP() vs List() vs Array()
OpenConsole("TEST MAP() vs List() vs Array()")
GuiWindow("TEST Map() vs List() vs Array() performance",800,600)
e=0
EditorGadget(0,5,5,790,590)
h
max=10000
LOOP=200000
LF$=Chr(10)
NewMap TestMap.l()
NewList TestList.l()
Dim TestArray.l(max)
out$="Purebasic Map() vs List() vs Array() performance test and comparison"+lf$
out$+" Test on "+StrU(max)+" element size"+Chr(10)+Chr(10)
;-------------------------------------------------
Out$+"Sequential fill element with constant value test :"+LF$
start = ElapsedMilliseconds()
For t=1 To max ; fill map()
TestMap(StrU(t))=t
Next
fillMap=ElapsedMilliseconds() -Start
start = ElapsedMilliseconds()
For t=1 To max ; fill List()
AddElement(TestList()):TestList()=t
Next
fillList = ElapsedMilliseconds()-start
start = ElapsedMilliseconds()
For t=1 To max ; fill Array()
TestArray(t)=t
Next
FillArray = ElapsedMilliseconds()-start
out$ + "=== Test === Result ===( Sequential fill With "+StrU(max)+" elements" +lf$
out$ + "Fill Array = "+StrU(FillArray) + " ms"+ LF$
out$ + "Fill MAP = "+StrU(fillMap) + " ms"+ LF$
out$ + "Fill List = "+StrU(fillList) + " ms"+ LF$+lf$
;------------------------------------------------
Out$+"Random index to fill element with constant value test :"+LF$
start = ElapsedMilliseconds()
For t = 1 To LOOP
TestMap(StrU(Random(max,1)))=5544
Next
randomFillMap=ElapsedMilliseconds()-start
start = ElapsedMilliseconds()
max=max-1
For t = 1 To LOOP
SelectElement(TestList(),Random(max-1,0))
TestList()=5544
Next
randomFillList=ElapsedMilliseconds()-start
max=max+1
start = ElapsedMilliseconds()
For t = 1 To LOOP
TestArray(Random(max,1))=5544
Next
randomFillArray=ElapsedMilliseconds()-start
out$ + "=== Test === Result ===(random fill into "+StrU(max)+" elements by "+StrU(loop)+"loops" +lf$
out$ + "Fill Array = "+StrU(randomFillArray) + " ms"+LF$
out$ + "Fill MAP = "+StrU(randomFillMap) + " ms"+ LF$
out$ + "Fill List = "+StrU(RandomfillList) + " ms"+ LF$+lf$
;------------------------------------------------
Out$+"Random index to retrieve value from element test :"+LF$
start = ElapsedMilliseconds()
For t = 1 To LOOP
TestMap(StrU(Random(max,1)))=5544
Next
randomGetMap=ElapsedMilliseconds()-start
start = ElapsedMilliseconds()
max=max-1
For t = 1 To LOOP
SelectElement(TestList(),Random(max-1,0))
TestList()=5544
Next
randomGetList=ElapsedMilliseconds()-start
max=max+1
start = ElapsedMilliseconds()
For t = 1 To LOOP
TestArray(Random(max,1))=5544
Next
randomGetArray=ElapsedMilliseconds()-start
out$ + "=== Test === Result ===(random retrieve in "+StrU(max)+" elements by "+StrU(loop)+"loops" +lf$
out$ + "Get Array = "+StrU(randomFillArray) + " ms"+LF$
out$ + "Get MAP = "+StrU(randomFillMap) + " ms"+ LF$
out$ + "Get List = "+StrU(RandomfillList) + " ms"+ LF$+lf$
Print(out$)
AddGadgetItem(e,0,out$)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Purebasic Map() vs List() vs Array() performance test and comparison
Test on 10000 element size
Sequential fill element with constant value test :
=== Test === Result ===( Sequential fill With 10000 elements
Fill Array = 0 ms
Fill MAP = 8 ms
Fill List = 0 ms
Random index to fill element with constant value test :
=== Test === Result ===(random fill into 10000 elements by 200000loops
Fill Array = 2 ms
Fill MAP = 87 ms
Fill List = 547 ms
Random index to retrieve value from element test :
=== Test === Result ===(random retrieve in 10000 elements by 200000loops
Get Array = 2 ms
Get MAP = 80 ms
Get List = 557 ms
conclusion :
assigning value is as fast for array , list or map
but in random retrieve speed, map have a very good edge over list
so , i would recommend a priority for Array > Map > List
do not use LIST , use MAP instead !
cheers
