Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30719 > unrolled thread

Re: fastest data structure for retrieving objects identified by (x, y) tuple?

Started byBenjamin Jessup <bsj@abzinc.com>
First post2012-10-04 08:21 -0400
Last post2012-10-04 14:04 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: fastest data structure for retrieving objects identified by (x, y) tuple? Benjamin Jessup <bsj@abzinc.com> - 2012-10-04 08:21 -0400
    Re: fastest data structure for retrieving objects identified by (x, y) tuple? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-04 14:04 +0000

#30719 — Re: fastest data structure for retrieving objects identified by (x, y) tuple?

FromBenjamin Jessup <bsj@abzinc.com>
Date2012-10-04 08:21 -0400
SubjectRe: fastest data structure for retrieving objects identified by (x, y) tuple?
Message-ID<mailman.1793.1349353325.27098.python-list@python.org>
On 10/4/2012 12:20 AM, python-list-request@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=10000, repeat=7)))
import platform
print(platform.python_version())

On my system, I get:
0.719622326348
2.7.1

[toc] | [next] | [standalone]


#30729

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-10-04 14:04 +0000
Message-ID<506d9765$0$29978$c3e8da3$5496439d@news.astraweb.com>
In reply to#30719
On Thu, 04 Oct 2012 08:21:13 -0400, Benjamin Jessup wrote:

> On 10/4/2012 12:20 AM, python-list-request@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?
[snip code]


I don't know. Is this a trick question? Is the answer, "nothing is wrong"?

It doesn't seem to be very useful code, but since I don't know what you 
think you are testing, I can't tell you whether you are doing it wrong or 
not.



-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web