list.count() and speed

BlitzMax Forums/BlitzMax Beginners Area/list.count() and speed

Ant(Posted 2006) [#1]
Hi, at the moment I am storing a variable which keeps track of how many objects are in my list. I would rather just use the list.count() method, but wondered if accessing this method would be significantly slower then updating a seperate varaible which tracks how many objects are in the list? (possibly negligable but I just wanted to check). I wouldnt be accessing the .count() method every frame.....or is this something too small to be concerned about?


sswift(Posted 2006) [#2]
Only if you had thousands of objects in said list, or needed to get that number thousands of times a frame would it amount to anything worth concerning yourself about.


tonyg(Posted 2006) [#3]
Ant,
As sswift said.
However, you can check this sort of thing easily yourself...
Type ttest
  Global mylist=CreateList()
End Type
For x = 1 To 10000
  my:ttest = New ttest
  ListAddLast ttest.mylist,my
Next
start=MilliSecs()
Print CountList(ttest.mylist)
Print MilliSecs()-start



Duckstab[o](Posted 2006) [#4]
Plus you should also take into account the size of the type

ie
10,000,000 types with 2 variables take 198 ms

10,000,000 types with 12 variables take 619 ms

so as types increase in size the count is slowed also

using field x[12] will make the count speed up some
ie a field array of five will make it faster than 5 fields
549 ms


tonyg(Posted 2006) [#5]
Hmmm.. few quick tests don't show a difference in speed with more variables in the type.
Listcount seems to counts the number of links on a list.
How would that be affected by the size of object?


sswift(Posted 2006) [#6]
I'm pretty sure Duckstabo is mistaken. The size of the elements in the list itself is fixed. There is one pointer which points to your type. There is no reason for the count function to ever look at your type. It should only look at the elements in the list, and ignore that pointer to your type.


DJWoodgate(Posted 2006) [#7]
I guess the size of the object becomes relevant when you have a limited amount of physical memory.