2-D dist functions
Chad Netzer
cnetzer at mail.arc.nasa.gov
Fri May 30 16:51:40 EDT 2003
On Thu, 2003-05-29 at 07:32, Brandon Corfman wrote:
> However, the thing is that's strange to me is that get_dist1 is slower
> than get_dist2.
> def tester():
> t = time.time()
> for i in range(0,1000000):
> Shouldn't using math.hypot be faster? If not, why not?
It is for me on my machine, but I have 1 Gig of RAM. You are creating a
BIG list inside the timing loop. Change range(0, 1000000) to
xrange(1000000), or build the list outside the loop.
ie:
test_range = range(1000000)
for i in test_range:
or even:
test_range = xrange(1000000)
for i in test_range:
Report back if the test results do not change.
By the way, you have a FAST machine. Mine takes 15 seconds to complete
test1, yours takes less than 3 (I'm on a 800 Mhz PIII). What are you
running (and how much RAM)?
--
Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)
More information about the Python-list
mailing list