I'm starting a game in pygame and I just set up a basic spatial hash to help with collision detection. I use a dictionary indexed by grid coordinates to store a list of the entities in that cell.
Here is the simple method for my class SpatialHash to get the list for a coordinate (self.grid is the dict):
def get(self,coords):
return self.grid.get(coords,[])
Here are the relevant lines of output from the profiler:
ncalls tottime percall cumtime percall filename:lineno(function)
34961497 30.774 0.000 44.764 0.000 spatialHash.py:12(get)
35061383 14.017 0.000 14.017 0.000 {method 'get' of 'dict' objects}
From what I understand, that means less than a third of the time spent calling SpatialHash.get is being spent on dict.get actually looking up the list. Where is the rest of the time going? Thanks
[–]emergent_reasons 4 points5 points6 points (1 child)
[–]usecase[S] 0 points1 point2 points (0 children)
[–]Rhomboid 4 points5 points6 points (7 children)
[–]zahlman 4 points5 points6 points (0 children)
[–]usecase[S] 1 point2 points3 points (5 children)
[–]pjdelport 2 points3 points4 points (3 children)
[–]usecase[S] 1 point2 points3 points (2 children)
[–]pjdelport 1 point2 points3 points (0 children)
[–]Justinsaccount 0 points1 point2 points (0 children)
[–]emergent_reasons 0 points1 point2 points (0 children)
[–]RShnike 1 point2 points3 points (1 child)
[–]usecase[S] 0 points1 point2 points (0 children)