Interesting timing issue I noticed
fetchinson at googlemail.com
Tue Apr 15 03:11:44 CEST 2008
> The project I'm working on is motion detection, involving a bit of image
> processing. No worries: no image processing background needed.
> Suffice to say that I initially wrote a script that goes through every pixel
> of a 320x240 picture (turned into an array using PIL) and performs some
> calculatiosn. It simply goes through every pixel in the array and performs a
> simple subtraction with a known value. The idea is to try to find
> differences between the two images.
> After a while, to try to speed up the calculations, I realized that I didn't
> need to do all 320x240 calculations. So I implemented a slightly more
> sophisticated algorithm and localized my calculations. I still do the pixel
> subtractions, but I do it on a smaller scale.
> Surprisingly, when I used time.time() to time the procedures, I find that
> doing all 320x240 calculations are often faster! On my machine, the former
> gives me on average an execution time of around 0.125s (and consistently),
> whereas the latter on average takes 0.160s.
> Why does this happen?
It's hard to tell without looking at a stripped down, minimal version
of your code that still shows the above behaviour. Most probably you
are not computationally bound and the majority of the execution time
is spent on memory read/write. For example it might happen that the
version of your code that has less number of FLOPS accesses the memory
More information about the Python-list