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


Groups > comp.lang.python > #30718

Re: Python-list Digest, Vol 109, Issue 20

Date 2012-10-04 08:20 -0400
From Benjamin Jessup <bsj@abzinc.com>
Organization ABZ, Inc.
Subject Re: Python-list Digest, Vol 109, Issue 20
References <mailman.6344.1349324402.27097.python-list@python.org>
Newsgroups comp.lang.python
Message-ID <mailman.1792.1349353254.27098.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python-list Digest, Vol 109, Issue 20 Benjamin Jessup <bsj@abzinc.com> - 2012-10-04 08:20 -0400

csiph-web