Help regarding python run time

Ian Kelly ian.g.kelly at gmail.com
Wed May 20 11:23:25 EDT 2015


On Wed, May 20, 2015 at 7:02 AM, AKHIL RANA <AKHILR at iitk.ac.in> wrote:
> Hi,
>
> I am student at IIT Kanpur and working on a Opencv based Python project. I
> am working on program development which takes less time to execute. For that
> i have tested my small program hello word on python to now the time taken by
> this program. I had run many time. and every time it run it gives me a
> different run time.
>
> Can we some how make the program to run at constant time so that we can work
> on how to reduce the timing ?

Not practically. The exact run time is dependent on a lot of factors
that are mostly out of your control: what other programs are running,
what they're doing and what resources they're using at that moment;
what hardware interrupts occur while your program is running; is data
to be read from disk cached or not; is data to be loaded from RAM
cached or not; if the disk is mechanical, what cylinder and sector
does the read head happen to be at when it gets a read request.

Instead of trying to measure an exact time over one run, you will get
better results by running the program several times and then taking
the minimum measurement as representative of the program's runtime
under ideal conditions.



More information about the Python-list mailing list