get-a-cup-of-coffee slow (fwd)
Grant Griffin
not.this at seebelow.org
Fri Aug 10 09:29:31 EDT 2001
Michael Linnemann wrote:
>
> Am Thu, 09 Aug 2001 18:12:31 -0400 Lulu of the Lotus-Eaters wrote:
>
> >In expanded form:
> >
> > def gen_sectors3():
> > print 'Generating (Version 3)...',
> > lst = []
> > for i in xrange(65536):
> > lst.append(chr(i & 0xFF))
> > for i in xrange(65536):
> > lst.append(chr((65535 - i) & 0xFF))
> > print 'done'
> > return ''.join(lst)
>
> >I haven't benched it--or even run it--but this will probably even beat
> >'gen_sectors2()'.
>
> But I did ;-)
>
> And here is the result:
>
> Version 2: 0.006
> Version 3: 1.005
> Version 4: 0.054
>
> I made a gen_sectors4 because V.2 was surprisingly slow:
>
> def gen_sectors4():
> print 'Generating (Version 4)...',
> s = []
> forward = []
> reverse = []
> for i in xrange(256):
> forward += [chr(i)]
> reverse += [chr(255 - i)]
How about?:
forward.append(chr(i))
reverse.append(chr(i))
> s += forward * 256
> s += reverse * 256
> print 'done'
> return "".join(s)
>
> This is Python2.0 on a Linux machine, only in case it matters...
Cool! But that one also seems kindda slow compared to #2. I wonder if
the lists were built using "append" (appending one element) rather than
"+=" (appending a list _containing_ one element).
there-are-obviously-many-"obvious"-ways-to-do-it-<wink>-ly y'rs,
=g2
--
_____________________________________________________________________
Grant R. Griffin g2 at dspguru.com
Publisher of dspGuru http://www.dspguru.com
Iowegian International Corporation http://www.iowegian.com
More information about the Python-list
mailing list