Possible memory leak?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Jan 25 18:52:25 EST 2006


On Wed, 25 Jan 2006 13:17:25 -0800, Tuvas wrote:

> Very interesting results with the last test. I guess I go back to my
> other code then, even if it is only a hair faster, it's still faster...

Can you say "premature optimization"?

Have you timed your code with realistic data? Not somebody else's code.
Not some cut back piece of sample code with only three lines. Unless you
have timed YOUR code, you don't know what's faster. 

Anyway, do you really care about "optimizing" code that takes an hour to
run to 59 minutes, 59 seconds, 997 milliseconds? Or, at the other extreme,
from 80 milliseconds to 77? Do you think anyone will notice?

I hope you do speed up your code, whatever way it takes. But I'm guessing
that if you aren't using the array module, you aren't getting anywhere
*near* as fast as you could be. (And that is JUST a guess -- time it to be
sure.)

>  It's odd, I just ran another test. There's 2 ways I can call my
> load_pic function, first of all, through taking a picture, secondly by
> loading a picture. For some reason, the exact same function takes the
> same amount of time when the load picture function is used, but not
> when called from the take picture function. Odd, isn't it... I don't
> know why the time would increase for one, but not for the other. The
> data is passed in exactly the same format, it's just really odd... Oh
> well, I'll get something figured out...

What are you timing? Are you timing the execution time of the code, or the
elapsed time? They are not the same thing. Hint: think about your
operating system and what it is doing. Can you say "preemptive
multitasking"? Are you measuring network events, memory paging,
screen savers, disk I/O? Are the files you are loading from disk badly
fragmented?

If your code is not optimized for memory, and hence pages a lot, you
should be including that time in your measurements. But you probably don't
want to count elapsed time when the screen saver kicks in.


-- 
Steven.




More information about the Python-list mailing list