get-a-cup-of-coffee slow (fwd)
Grant Griffin
not.this at seebelow.org
Fri Aug 10 10:50:17 EDT 2001
In article <3B73E1BB.6825C31A at seebelow.org>, Grant says...
>
>Michael Linnemann wrote:
>>
...
>>
>> And here is the result:
>>
>> Version 2: 0.006
>> Version 3: 1.005
>> Version 4: 0.054
>>
Here's my results. (Some new versions are also benchmarked below):
Using repeated string "+=":
Generating (Version 1)... done
1.507583 minutes
Using string multiplication (this is by far the fastest one yet):
Generating (Version 2)... done
0.000098 minutes
Using list "+=" of "[chr()]":
Generating (Version 3a)... done
0.013425 minutes
Using list append of "chr" (which is slightly faster):
Generating (Version 3b)... done
0.012451 minutes
Using list comprehensions (faster yet):
s = [chr(i & 0xFF) for i in xrange(65536)]
s += [chr((65535 - i) & 0xFF) for i in xrange(65536)]
Generating (Version 3c)... done
0.009393 minutes
Using array.array('c'):
Generating (Version 4a)... done
0.008935 minutes
Using an array initialized via a list comprehension (I thought this might be
faster because it would "pre-allocate" the array, but it wasn't):
s = array.array('c', [chr(0) for x in xrange(2 * 65536)])
Generating (Version 4b)... done
0.016283 minutes
trying-not-to-think-of-how-many-ways-it-could-be-done-in-perl
-for-fear-my-head-will-explode-<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