string copying

Bengt Richter bokr at oz.net
Sat Mar 30 00:52:46 EST 2002


On Fri, 29 Mar 2002 19:22:45 -0500, Tim Peters <tim.one at comcast.net> wrote:

>[Peter Hansen]
>> The only one I've been able to think of is the surprisingly
>> common situation of trying to consume vast quantities of memory
>> quickly by something like:
>>
>> a = [0] * 1000000
>> for i in xrange(1000000):
>>     a[i] = 'bigstringsuckinguplotsofmemory'
>
>Hmm.  A much easier way to consume vast quantities of memory quickly is to
>skip the for-loop and just increase the multiplier on the first line.  If
>you're on a 32-bit machine, and want to consume N bytes, use N/4 as the
>multiplier.
>
s = 'x'*2**30 would be a quick gig too. But it made me think maybe one could
write a sort of memory test (to exercise the available python space, anyway).
Does python run out of memory gracefully? I'm afraid to try it (have NT4, 320MB,
and too many things running a lot).

Anyway, one could generate binary patterns and chr() the 8-bit pieces and join
them into say megabyte chunks, and then compare sequentially with a the regenerated
sequence. And do it for different patterns. Not like doing it from a bootable floppy,
but still some exercise. You could use long random sequences. ... hm, I wonder if
dual CPUs running in a dedicated test would have a better chance of jangling
motherboard signals with patterns beating against each other than a single CPU...

Regards,
Bengt Richter



More information about the Python-list mailing list