Integer From A Float List?!?

Discussion in 'Python' started by andrea_gavana@tin.it, Mar 5, 2005.

  1. Guest

    Hello NG,

    probably because I still have Python 2.3.4, these are the results I'm
    getting:


    C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints
    = m
    ap(int, floats)"
    1000 loops, best of 3: 398 usec per loop

    C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints
    = [
    int(x) for x in floats]"
    1000 loops, best of 3: 820 usec per loop

    C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" "ints
    = [
    ]" "for x in floats: ints.append(int(x))"
    1000 loops, best of 3: 932 usec per loop

    C:\Python23\Lib>python timeit.py -s "floats = map(float, range(1000))" -s
    "from
    itertools import starmap, izip" "ints = list(starmap(int, izip(floats)))"
    1000 loops, best of 3: 513 usec per loop


    So, the last (very smart) solution, works slightly slower on my PC wrt the
    first solution. I don't know really what has changed in Python 2.4... At
    the moment I cannot switch to 2.4 because some site-packages I use are still
    not updated to Python 2.4.

    Anyway, thanks to you all for your smart suggestion. It is really a nice
    newsgroup.

    Andrea.
     
    , Mar 5, 2005
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    7
    Views:
    6,634
    Roedy Green
    May 10, 2004
  2. Jim West
    Replies:
    4
    Views:
    1,867
    Jeff Schwab
    Jan 16, 2004
  3. Jukka Lehtonen

    operator== (float, float)

    Jukka Lehtonen, Aug 4, 2004, in forum: C++
    Replies:
    5
    Views:
    2,692
    Jukka Lehtonen
    Aug 5, 2004
  4. Replies:
    0
    Views:
    355
  5. Bill Mill

    Re: Integer From A Float List?!?

    Bill Mill, Mar 4, 2005, in forum: Python
    Replies:
    1
    Views:
    3,834
    George Sakkis
    Mar 5, 2005
  6. Nick Coghlan

    Re: Integer From A Float List?!?

    Nick Coghlan, Mar 5, 2005, in forum: Python
    Replies:
    3
    Views:
    425
    Peter Otten
    Mar 6, 2005
  7. Replies:
    1
    Views:
    337
    Kent Johnson
    Mar 5, 2005
  8. Carsten Fuchs
    Replies:
    45
    Views:
    2,311
    James Kanze
    Oct 8, 2009
Loading...