Loop performance disappearance

Mikael Johansson mikael.johansson at helsinki.lzx
Wed Mar 15 15:35:19 CET 2000

Hello Remco!

Remco Gerlich wrote:

> Mikael Johansson wrote in comp.lang.python:
> > for i in range(loops):
> >     pass
> >
> > If loops=500 000 (space added for clarity) the "program" executes in ~2
> > secs on my machine. But if loops is set to 5 000 000, the execution time
> > rises to substantially more than tenfold (I terminated it after one
> > minute). However the CPU-load is quite small, most of the time is spent
> > disk swapping like crazy!
> That's because range(loops) is a list. It actually has to construct a list
> that size, and then walks through it. 5 million doesn't fit in your memory
> and it starts swapping.

OK, that of course explains it. Thanks!

Have a nice day,
    Mikael J.
    for email correct domain

More information about the Python-list mailing list