On Fri, Jun 3, 2011 at 3:53 PM, Gabriel <snoopy.6...@googlemail.com> wrote:
> But still, is this solution really faster or better than the one using
> list comprehension and the expression 'x*x'?

No, not really.

>c:\python32\python -m timeit -s "coords = list(range(100))" -s "from math 
>import hypot" -s "from functools import reduce" "reduce(hypot, coords, 0)"
10000 loops, best of 3: 53.2 usec per loop

>c:\python32\python -m timeit -s "coords = list(range(100))" -s "from math 
>import sqrt, fsum" "sqrt(fsum(x*x for x in coords))"
10000 loops, best of 3: 32 usec per loop

>c:\python32\python -m timeit -s "coords = list(range(100))" -s "from math 
>import sqrt" "sqrt(sum(x*x for x in coords))"
100000 loops, best of 3: 14.4 usec per loop
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to