performance question

Manuel Garcia news at manuelmgarcia.com
Wed Feb 12 20:15:11 CET 2003


On 12 Feb 2003 15:40:53 +0000, Paul Rudin <Paul_Rudin at scientia.com>
wrote:

>
>I'm writing a couple of scripts and, more out of curiosity that
>anything else, I thought I'd run the profiler over the code, to see if
>I could identify any worthwhile speedups.
>
>I've noticed some behaviour that I don't really understand. Repeated
>invocations of the same bit of code under the profiler in the same
>interpreter instance take longer and longer to execute. Kill the
>interpreter and do each run in a new session and they take roughly the
>amount of time.
>
>At first I thought they maybe something to do with garbage collection
>could explain this. But I used gc.set_threshold(0) and an explicit
>gc.collect() before each run and I still see the same thing. 
>
>Each invocation works on the same data - a rather long string bound to
>a global variable. But there's no state in my code that could account
>for the difference (or at least not that I'm aware of). The profiler
>reports exactly the same number of calls of each function for each
>invocation.
>
>Can anyone suggest why I'm seeing this behaviour?

Maybe your program is keeping references to things you actually are
done using.  As long as a single reference exists to something, GC
leaves it alone.

If you have reference cycles and set the __del__ method, these cycles
are stored in gc.garbage forever, until you manually break the
reference links to get rid of the cycles.

Do you have any OS statistics on memory page faults?

Can you post code?

You are correct in thinking that this behavior is not typical.

Manuel




More information about the Python-list mailing list