Integer From A Float List?!?
kent37 at tds.net
Sat Mar 5 14:04:44 CET 2005
andrea_gavana at tin.it wrote:
> Hello NG,
> sorry to bother you again with this question... I never used the "timeit"
> function, and I would like to ask you if the call I am doing is correct:
> C:\Python23\Lib>python timeit.py -n 1000 -s "from Numeric import ones" -s
> ts=ones((1000,1),'f')" -s "ints = floats.astype(int)"
> 1000 loops, best of 3: 0.0536 usec per loop
The -s option indicates Setup steps that are done outside the timing loop. So you have timed 1000
empty loops, which is indeed impressively fast :-)
The correct command is
C:\Python23\Lib>python23 timeit.py -n 1000 -s "from Numeric import ones" -s
"floats=ones((1000,1),'f')" "ints = floats.astype(int)"
1000 loops, best of 3: 30.7 usec per loop
which is still impressively fast compared to map:
C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints= map(int, floats)"
1000 loops, best of 3: 572 usec per loop
> I used Numeric module to create a 1000 floats matrix of ones, and it seems
> to me that is a lot faster than other solutions... but probably I am doing
> something wrong in my call to the timeit function...
> Thank you a lot.
More information about the Python-list