On 20-5-2015 17:23, Ian Kelly wrote: > On Wed, May 20, 2015 at 7:02 AM, AKHIL RANA <akh...@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. >
Or measure the actual CPU clock cycles taken instead of the wall clock run time. Then you should get a fairly constant number, if the program does the same work every time you run it. phobos:~ irmen$ time python test.py real 0m3.368s user 0m0.214s <--- cpu time spent in user mode actually doing work sys 0m0.053s Irmen -- https://mail.python.org/mailman/listinfo/python-list