[Tutor] Why does counting to 20 million stress my computer?
Magnus Lyckå
magnus at thinkware.se
Fri Jul 16 13:16:13 CEST 2004
At 03:19 2004-07-16 -0700, Dick Moores wrote:
> Why does counting to 20 million stress my computer?
Beause you are building very big lists that exhausts your RAM.
"range(x)" will return a list with x pointers to x integers. I
assume both the pointers and the integer items use 4 bytes each,
so besides various overhead you are allocating (4+4)*20 000 000 =
160 MB of main memory for the counter. Not very effective, is it?
Try replacing "range(max)" with "xrange(max)".
No need for a degree, just read the manual:
http://docs.python.org/lib/built-in-funcs.html
--
Magnus Lycka (It's really Lyckå), magnus at thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language
More information about the Tutor
mailing list