Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90958 > unrolled thread

Re: Help regarding python run time

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2015-05-20 09:23 -0600
Last post2015-05-20 10:26 -0600
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Help regarding python run time Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-20 09:23 -0600
    Re: Help regarding python run time Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-05-20 17:48 +0200
      Re: Help regarding python run time Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-20 10:26 -0600

#90958 — Re: Help regarding python run time

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-05-20 09:23 -0600
SubjectRe: Help regarding python run time
Message-ID<mailman.172.1432135454.17265.python-list@python.org>
On Wed, May 20, 2015 at 7:02 AM, AKHIL RANA <AKHILR@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.

[toc] | [next] | [standalone]


#90962

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2015-05-20 17:48 +0200
Message-ID<555cacd9$0$2934$e4fe514c@news2.news.xs4all.nl>
In reply to#90958
On 20-5-2015 17:23, Ian Kelly wrote:
> On Wed, May 20, 2015 at 7:02 AM, AKHIL RANA <AKHILR@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

[toc] | [prev] | [next] | [standalone]


#90966

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-05-20 10:26 -0600
Message-ID<mailman.176.1432139258.17265.python-list@python.org>
In reply to#90962
On Wed, May 20, 2015 at 9:48 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote:
> 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

And yet:

$ time python3 primes.py

real 0m1.101s
user 0m1.099s
sys 0m0.000s
$ time python3 primes.py

real 0m1.135s
user 0m1.128s
sys 0m0.004s
$ time python3 primes.py

real 0m1.162s
user 0m1.147s
sys 0m0.013s

http://unix.stackexchange.com/questions/162115/why-does-the-user-and-sys-time-vary-on-multiple-executions

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web