Re: fastest data structure for retrieving objects identified by (x, y) tuple?
On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: How do you know that? No offence, but if you can't even work out whether lookups in a dict or a list are faster, I can't imagine why you think you can intuit what the fastest way to retrieve the nearest neighbours would be. Whats wrong with the test below? # randomly select matrix coordinates to look-up from random import randrange test_coords = [] for i in range(1000): x = randrange(2400); y = randrange(2400); test_coords.append((x, y)) # build objects class Object():pass obj1 = Object(); obj2 = Object(); obj1.up = obj2 # build some test code from timeit import Timer setup = "from __main__ import test_coords, obj1, obj2" t = Timer("for p in test_coords: obj = obj1.up", setup) # run the test code print(min(t.repeat(number=1, repeat=7))) import platform print(platform.python_version()) On my system, I get: 0.719622326348 2.7.1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 109, Issue 20
On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: How do you know that? No offence, but if you can't even work out whether lookups in a dict or a list are faster, I can't imagine why you think you can intuit what the fastest way to retrieve the nearest neighbours would be. Whats wrong with the test below? # randomly select matrix coordinates to look-up from random import randrange test_coords = [] for i in range(1000): x = randrange(2400); y = randrange(2400); test_coords.append((x, y)) # build objects class Object():pass obj1 = Object(); obj2 = Object(); obj1.up = obj2 # build some test code from timeit import Timer setup = "from __main__ import test_coords, obj1, obj2" t = Timer("for p in test_coords: obj = obj1.up", setup) # run the test code print(min(t.repeat(number=1, repeat=7))) import platform print(platform.python_version()) On my system, I get: 0.719622326348 2.7.1 -- http://mail.python.org/mailman/listinfo/python-list
fastest data structure for retrieving objects identified by (x,y) tuple?
I have a group of objects identified by unique (x,y) pairs and I want to find out an object's "neighbors" in a matrix of size 2400 x 2400. # #obj# # # # # # #obj# 3 x 3 Example # # # # # # There is either a neighbor, or a null value. I always know the (x,y) pair to check the neighbors of, so is doing, >> obj = grid[x][y] #lists, doesn't scale with num of objects or, >> obj = grid.get((x,y),None) #dictionary, scales with num of objects the fastest? I can't seem to find a conclusion by testing each alone, then in the full environment. Is it that, depending on the number of objects, each has an advantage? I know the fastest way to retrieve them would be to have them store pointers to their neighbors, then use those for retrieval. When large numbers of objects are changing their (x,y) pairs, rebuilding the pointers is too slow. -- http://mail.python.org/mailman/listinfo/python-list
[python-list] python application file format
Hello all, What do people recommend for a file format for a python desktop application? Data is complex with 100s/1000s of class instances, which reference each other. Write the file with struct module? (Rebuild object pointers, safe, compact, portable, not expandable without reserved space) Use cPickle with a module/class whitelist? (Can't easily port, not entirely safe, compact enough, expandable) Use JSON or similar? (Rebuild object pointers, portable, expandable, size?) Any advice is greatly appreciated! -- http://mail.python.org/mailman/listinfo/python-list