470,815 Members | 1,272 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Measuring running time in a general + portable way

Hi,

I'm trying to find a decent way of measuring the running time of a
long-running program.
Say, the running time ranges from several seconds to more than a day.

The standard clock() function seems inadequate for this task.
(I read somewhere in this group that clock_t would likely overflow
after <1 hour).

Is there any better solution that can deal with this and be portable?
Thank you.

Apr 26 '07 #1
20 1774
On 25 Apr 2007 17:52:27 -0700, upperclass <th********@gmail.comwrote:
>Hi,

I'm trying to find a decent way of measuring the running time of a
long-running program.
Say, the running time ranges from several seconds to more than a day.

The standard clock() function seems inadequate for this task.
(I read somewhere in this group that clock_t would likely overflow
after <1 hour).

Is there any better solution that can deal with this and be portable?
Thank you.
IIANM, difftime will portably give you the difference between two wall
clock times. See time.h. If you have posix (widely available) you can
a finer resolution than seconds.

Apr 26 '07 #2
Richard Harter wrote:
>
NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
Your clock is in serious error.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline.net

--
Posted via a free Usenet account from http://www.teranews.com

Apr 26 '07 #3
On Thu, 26 Apr 2007 00:25:27 -0400, CBFalconer <cb********@yahoo.com>
wrote:
>Richard Harter wrote:
>>
NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500

Your clock is in serious error.
Huh???
Apr 26 '07 #4
Richard Harter wrote:
On Thu, 26 Apr 2007 00:25:27 -0400, CBFalconer <cb********@yahoo.com>
wrote:
>>Richard Harter wrote:
>> NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500

Your clock is in serious error.

Huh???
date
Thu Apr 26 18:58:54 NZST 2007

Your posting was dated 04/27/07 06:54

--
Ian Collins.
Apr 26 '07 #5
On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>Richard Harter wrote:
>On Thu, 26 Apr 2007 00:25:27 -0400, CBFalconer <cb********@yahoo.com>
wrote:
>>>Richard Harter wrote:

NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500

Your clock is in serious error.

Huh???

date
Thu Apr 26 18:58:54 NZST 2007

Your posting was dated 04/27/07 06:54
I am puzzled. The header info is:

Path:
border1.nntp.dca.giganews.com!nntp.giganews.com!lo cal01.nntp.dca.giganews.com!nntp.rapidnet.com!news .rapidnet.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
From: cr*@tiac.net (Richard Harter)
Newsgroups: comp.lang.c
Subject: Re: Measuring running time in a general + portable way
Date: Thu, 26 Apr 2007 13:22:00 GMT
Message-ID: <46****************@news.sbtc.net>
References: <11**********************@r30g2000prh.googlegroups .com>
X-Newsreader: Forte Free Agent 1.1/32.230
Lines: 21
NNTP-Posting-Host: 208.53.229.199
X-Trace:
sv3-rXZz57965mmdYAuUVuQRD17DWMURcFlXdXbDMUfMXl43d/T9ZXu6mX3LcF/m6gzUkMzDCQCu+XGcizQ!9GakYvoucalohljq5M2o1XqHkbjAC 2SCYvRKqvGjmKFnu/DwLjRCBkrPNmJTaIsnZs6DYQpsDns=
X-Complaints-To: ab***@rapidnet.com
X-DMCA-Complaints-To: ab***@rapidnet.com
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
X-Postfilter: 1.3.34
Xref: number1.nntp.dca.giganews.com comp.lang.c:743832

Where are you getting this 04/27/07 06:54 from?
Apr 26 '07 #6
Richard Harter said:
On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>>Richard Harter wrote:
>>On Thu, 26 Apr 2007 00:25:27 -0400, CBFalconer
<cb********@yahoo.comwrote:

Richard Harter wrote:

NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500

Your clock is in serious error.

Huh???

date
Thu Apr 26 18:58:54 NZST 2007

Your posting was dated 04/27/07 06:54

I am puzzled.
Why? Have you never seen people make mistakes before?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 26 '07 #7
Richard Harter wrote:
On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.com>
wrote:

>>Richard Harter wrote:
>>>On Thu, 26 Apr 2007 00:25:27 -0400, CBFalconer <cb********@yahoo.com>
wrote:
Richard Harter wrote:
NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500

Your clock is in serious error.

Huh???

date
Thu Apr 26 18:58:54 NZST 2007

Your posting was dated 04/27/07 06:54


I am puzzled. The header info is:

Path:
border1.nntp.dca.giganews.com!nntp.giganews.com!lo cal01.nntp.dca.giganews.com!nntp.rapidnet.com!news .rapidnet.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
From: cr*@tiac.net (Richard Harter)
Newsgroups: comp.lang.c
Subject: Re: Measuring running time in a general + portable way
Date: Thu, 26 Apr 2007 13:22:00 GMT
In my view of the header (and probably Chuck's), Date (as set by your
agent) was 04/27/07 06:54, which usually happens when the sender system
clock is wrong. The NNTP-Posting-Date is set by the server.

Only your postings appear to be in the future.

--
Ian Collins.
Apr 26 '07 #8
On Thu, 26 Apr 2007 20:29:03 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>Richard Harter wrote:
>On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.com>
wrote:

>>>Richard Harter wrote:

On Thu, 26 Apr 2007 00:25:27 -0400, CBFalconer <cb********@yahoo.com>
wrote:
>Richard Harter wrote:
>
>
> NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
>
>Your clock is in serious error.

Huh???
date
Thu Apr 26 18:58:54 NZST 2007

Your posting was dated 04/27/07 06:54


I am puzzled. The header info is:

Path:
border1.nntp.dca.giganews.com!nntp.giganews.com!l ocal01.nntp.dca.giganews.com!nntp.rapidnet.com!new s.rapidnet.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
From: cr*@tiac.net (Richard Harter)
Newsgroups: comp.lang.c
Subject: Re: Measuring running time in a general + portable way
Date: Thu, 26 Apr 2007 13:22:00 GMT

In my view of the header (and probably Chuck's), Date (as set by your
agent) was 04/27/07 06:54, which usually happens when the sender system
clock is wrong. The NNTP-Posting-Date is set by the server.

Only your postings appear to be in the future.
This is very weird. My clock has the correct time and date. Moreover
the times show up correctly when I download them.
Apr 26 '07 #9
On Thu, 26 Apr 2007 07:42:51 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
>Richard Harter said:
>On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>>>Richard Harter wrote:
On Thu, 26 Apr 2007 00:25:27 -0400, CBFalconer
<cb********@yahoo.comwrote:

>Richard Harter wrote:
>
> NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
>
>Your clock is in serious error.

Huh???
date
Thu Apr 26 18:58:54 NZST 2007

Your posting was dated 04/27/07 06:54

I am puzzled.

Why? Have you never seen people make mistakes before?
Ian says he's seeing my posting as coming in the future. Do you see
this also?
Apr 26 '07 #10
Richard Harter said:
Richard Heathfield wrote:
>>Richard Harter said:
>>Ian Collins wrote:
<snip>
>>>>
Your posting was dated 04/27/07 06:54

I am puzzled.

Why? Have you never seen people make mistakes before?

Ian says he's seeing my posting as coming in the future. Do you see
this also?
No. In my view (er, literally!), he is mistaken.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 26 '07 #11

"Richard Harter" <cr*@tiac.netschrieb im Newsbeitrag
news:46****************@news.sbtc.net...
On Thu, 26 Apr 2007 07:42:51 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
>>Richard Harter said:
>>On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.com>
wrote:

Richard Harter wrote:
On Thu, 26 Apr 2007 00:25:27 -0400, CBFalconer
<cb********@yahoo.comwrote:
>
>>Richard Harter wrote:
>>
>> NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
>>
>>Your clock is in serious error.
>
Huh???
>

date
Thu Apr 26 18:58:54 NZST 2007

Your posting was dated 04/27/07 06:54

I am puzzled.

Why? Have you never seen people make mistakes before?

Ian says he's seeing my posting as coming in the future. Do you see
this also?
Yes.

Confused am with pm? I see a 12 hours difference

Bye, Jojo
Apr 26 '07 #12
Richard Heathfield wrote:
Richard Harter said:
>>Richard Heathfield wrote:
>>>Richard Harter said:

Ian Collins wrote:

<snip>
>>>>>Your posting was dated 04/27/07 06:54

I am puzzled.

Why? Have you never seen people make mistakes before?

Ian says he's seeing my posting as coming in the future. Do you see
this also?


No. In my view (er, literally!), he is mistaken.
I'm not, something software is!

Richard's postings appear to have a date 24 hours ahead of their
NNTP-Posting-Date.

--
Ian Collins.
Apr 26 '07 #13
Ian Collins said:
Richard Heathfield wrote:
<snip>
>In my view (er, literally!), [Ian Collins] is mistaken.
I'm not, something software is!

Richard [Harter]'s postings appear to have a date 24 hours ahead of
their NNTP-Posting-Date.
Ian, I spoke too soon and I owe you an apology.

Here is an extract from a Richard Harter header - in fact, it's taken
from the same header that he quoted himself in an effort to defend his
system:

NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
From: cr*@tiac.net (Richard Harter)
Newsgroups: comp.lang.c
Subject: Re: Measuring running time in a general + portable way
Date: Thu, 26 Apr 2007 13:22:00 GMT

The discrepancy between NNTP-Posting-Date and the apparent date is very
evident.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 26 '07 #14
Richard Harter wrote:
On Thu, 26 Apr 2007 20:29:03 +1200, Ian Collins <ia******@hotmail.comwrote:
>Richard Harter wrote:
>>On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.comwrote:
These posts show up here, converted to local time, as:

3:01 AM
3:27 PM
4:29 AM
5:16 PM

which smells like a 12 hour displacement in your time setting.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline.net

--
Posted via a free Usenet account from http://www.teranews.com

Apr 26 '07 #15
Richard Harter wrote:
CBFalconer <cb********@yahoo.comwrote:
>Richard Harter wrote:
>>>
NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500

Your clock is in serious error.

Huh???
Apologies. I misread the day.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline.net

--
Posted via a free Usenet account from http://www.teranews.com

Apr 26 '07 #16
Richard Heathfield wrote, On 26/04/07 11:59:
Ian Collins said:
>Richard Heathfield wrote:

<snip>
>>In my view (er, literally!), [Ian Collins] is mistaken.
I'm not, something software is!

Richard [Harter]'s postings appear to have a date 24 hours ahead of
their NNTP-Posting-Date.

Ian, I spoke too soon and I owe you an apology.

Here is an extract from a Richard Harter header - in fact, it's taken
from the same header that he quoted himself in an effort to defend his
system:

NNTP-Posting-Date: Wed, 25 Apr 2007 20:22:21 -0500
From: cr*@tiac.net (Richard Harter)
Newsgroups: comp.lang.c
Subject: Re: Measuring running time in a general + portable way
Date: Thu, 26 Apr 2007 13:22:00 GMT

The discrepancy between NNTP-Posting-Date and the apparent date is very
evident.
I suggest checking the timezone on the machine, AM/PM and the date. The
Date header says the time is in GMT and I don't think Richard Harter is
in a country using GMT as its timezone.

13:22 - 5:00 gives us 8:00 (I got the -5 from the offset on the posting
date).
An AM/PM error deals with the difference between 8:22 and 20:22.
--
Flash Gordon
Apr 26 '07 #17
On Thu, 26 Apr 2007 06:57:45 -0400, CBFalconer <cb********@yahoo.com>
wrote:
>Richard Harter wrote:
>On Thu, 26 Apr 2007 20:29:03 +1200, Ian Collins <ia******@hotmail.comwrote:
>>Richard Harter wrote:
On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.comwrote:

These posts show up here, converted to local time, as:

3:01 AM
3:27 PM
4:29 AM
5:16 PM

which smells like a 12 hour displacement in your time setting.
And so it is. Until I just changed it, it read 10:47 PM. It should be
okay now. Blush, blush.

Thanks muchly, everyone.
Apr 26 '07 #18
Richard Heathfield wrote:
>
Ian, I spoke too soon and I owe you an apology.
I think I've just found my new sig :)

--
Ian Collins.
Apr 26 '07 #19
CBFalconer <cb********@yahoo.comwrote:
Richard Harter wrote:
On Thu, 26 Apr 2007 20:29:03 +1200, Ian Collins <ia******@hotmail.comwrote:
Richard Harter wrote:
On Thu, 26 Apr 2007 19:01:11 +1200, Ian Collins <ia******@hotmail.comwrote:

These posts show up here, converted to local time, as:

3:01 AM
3:27 PM
4:29 AM
5:16 PM

which smells like a 12 hour displacement in your time setting.
Another proof that the 24-hour clock is superior to your poncy USAnian
12-hour one...

Richard, g,d,rlb
Apr 27 '07 #20
On Apr 25, 5:52 pm, upperclass <thammak...@gmail.comwrote:
I'm trying to find a decent way of measuring the running time of a
long-running program.
Say, the running time ranges from several seconds to more than a day.

The standard clock() function seems inadequate for this task.
(I read somewhere in this group that clock_t would likely overflow
after <1 hour).

Is there any better solution that can deal with this and be portable?
Well not really, but if overflow is your highest priority, then

#include <limits.h>
#include <time.h>

double monotimer (void (*something) (void * p), void * p) {
double dt, cdt;
time_t start = time (NULL), end;
clock_t cstart = clock(), cend;

something (p); /* Whatever you are timing */

dt = difftime (end = time (NULL), start);
cdt = (cend = clock ()) - cstart;
ock must have wrapped around (via difftime()) and simply offset that
to the clock difference (after casting to a large enough type, like
double or
if (dt >= floor (((double) ULONG_MAX) / CLOCKS_PER_SEC)) return
dt;
return cdt / (double) CLOCKS_PER_SEC;
}

So after around 50 days of running time you will switch from cycle
timer to wall clock time on Unix systems. On Windows both just
measure wall clock time in different units. So on Windows you could
do more by trying to calculate how many times the clock wrapped around
(after casting it to a double or an int64_t).

--
Paul Hsieh
http://www.pobox.com/~qed
http://bstring.sf.net/

Apr 27 '07 #21

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jonas Kölker | last post: by
6 posts views Thread by Matthew Nuzum | last post: by
74 posts views Thread by Dominik Wallner | last post: by
14 posts views Thread by artifact.one | last post: by
2 posts views Thread by upperclass | last post: by
9 posts views Thread by Ross | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.