Re: genexp performance problem?

2006-05-31 Thread Fredrik Lundh
Giovanni Bajo wrote: I found this strange: python -mtimeit sum(int(L) for L in xrange(3000)) 100 loops, best of 3: 5.04 msec per loop python -mtimeit import itertools; sum(itertools.imap(int, xrange(3000))) 100 loops, best of 3: 3.6 msec per loop I thought the two constructs could

Re: genexp performance problem?

2006-05-31 Thread Fredrik Lundh
Giovanni Bajo wrote: I found this strange: python -mtimeit sum(int(L) for L in xrange(3000)) 100 loops, best of 3: 5.04 msec per loop python -mtimeit import itertools; sum(itertools.imap(int, xrange(3000))) 100 loops, best of 3: 3.6 msec per loop I thought the two

Re: genexp performance problem?

2006-05-31 Thread Peter Otten
Giovanni Bajo wrote: I found this strange: python -mtimeit sum(int(L) for L in xrange(3000)) 100 loops, best of 3: 5.04 msec per loop python -mtimeit import itertools; sum(itertools.imap(int, xrange(3000))) 100 loops, best of 3: 3.6 msec per loop I thought the two constructs could

Re: genexp performance problem?

2006-05-31 Thread Giovanni Bajo
Fredrik Lundh wrote: I found this strange: python -mtimeit sum(int(L) for L in xrange(3000)) 100 loops, best of 3: 5.04 msec per loop python -mtimeit import itertools; sum(itertools.imap(int, xrange(3000))) 100 loops, best of 3: 3.6 msec per loop I thought the two constructs could

genexp performance problem?

2006-05-30 Thread Giovanni Bajo
Hello, I found this strange: python -mtimeit sum(int(L) for L in xrange(3000)) 100 loops, best of 3: 5.04 msec per loop python -mtimeit import itertools; sum(itertools.imap(int, xrange(3000))) 100 loops, best of 3: 3.6 msec per loop I thought the two constructs could achieve the same speed. --

RE: genexp performance problem?

2006-05-30 Thread Delaney, Timothy (Tim)
Giovanni Bajo wrote: python -mtimeit sum(int(L) for L in xrange(3000)) 100 loops, best of 3: 5.04 msec per loop python -mtimeit import itertools; sum(itertools.imap(int, xrange(3000))) 100 loops, best of 3: 3.6 msec per loop I thought the two constructs could achieve the same speed.

Re: genexp performance problem?

2006-05-30 Thread Kent Johnson
Delaney, Timothy (Tim) wrote: python -mtimeit sum(int(L) for L in xrange(3000)) 100 loops, best of 3: 6.76 msec per loop python -mtimeit -s g = (int(L) for L in xrange(3000)) sum(g) 100 loops, best of 3: 1.09 usec per loop The generator comprehension needs to create a new generator

RE: genexp performance problem?

2006-05-30 Thread Delaney, Timothy (Tim)
Kent Johnson wrote: Reusing the generator doesn't give a correct answer; after the first sum() the generator is exhausted: Duh - good point. I forgot it was returning a generator object, not generator function. Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list