get-a-cup-of-coffee slow (fwd)

Michael Linnemann m.linnemann at addcom.de
Fri Aug 10 11:47:41 CEST 2001


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)]
       s += forward * 256
       s += reverse * 256
       print 'done'
       return "".join(s)
       
This is Python2.0 on a Linux machine, only in case it matters...

Regards
Michael



More information about the Python-list mailing list