Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > C++

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-01-2008, 10:05 AM
jeremit0
 
Posts: n/a
Need timer with ability to time long intervals and sub-second precision

I need a timer that has sub-second precision and can time for longer
than 2 hours.

I have used the clock_t data type and the clock() function to
determine the elapsed time of a calculation. A problem arose when the
elapsed time was more than 1 hour and 20 minutes, the clock_t data
would wrap around and the time difference would become negative.

I started looking at using the time_t data type. It looks like it can
do a large enough time difference, but it lacks the sub-second
precision I desire.

Does anyone know if what I want is possible? Am I going to have to
use two different timers; one for long times and one for short times?

Thanks,
Jeremy

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #2 (permalink)  
Old 08-01-2008, 04:44 PM
Oncaphillis
 
Posts: n/a
Re: Need timer with ability to time long intervals and sub-second precision

jeremit0 wrote:

> I need a timer that has sub-second precision and can time for longer
> than 2 hours.


Hows about gettimeofday ?

http://www.opengroup.org/onlinepubs/...timeofday.html

If your system provides it

O.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #3 (permalink)  
Old 08-01-2008, 04:44 PM
Alberto Ganesh Barbati
 
Posts: n/a
Re: Need timer with ability to time long intervals and sub-second precision

jeremit0 ha scritto:
> I need a timer that has sub-second precision and can time for longer
> than 2 hours.
>
> I have used the clock_t data type and the clock() function to
> determine the elapsed time of a calculation. A problem arose when the
> elapsed time was more than 1 hour and 20 minutes, the clock_t data
> would wrap around and the time difference would become negative.
>
> I started looking at using the time_t data type. It looks like it can
> do a large enough time difference, but it lacks the sub-second
> precision I desire.
>
> Does anyone know if what I want is possible? Am I going to have to
> use two different timers; one for long times and one for short times?
>


Have you tried Boost.DateTime?

http://www.boost.org/doc/libs/1_35_0...date_time.html

the boost::ptime class uses 64-bits with microsecond resolution, which
should be quite enough for your needs.

Ganesh

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #4 (permalink)  
Old 08-01-2008, 04:57 PM
Thomas Richter
 
Posts: n/a
Re: Need timer with ability to time long intervals and sub-second precision

jeremit0 schrieb:
> I need a timer that has sub-second precision and can time for longer
> than 2 hours.


> Does anyone know if what I want is possible? Am I going to have to
> use two different timers; one for long times and one for short times?


Not in C++, but POSIX offers gettimeofday() which might do what you want.

Greetings,
Thomas

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #5 (permalink)  
Old 08-02-2008, 01:53 AM
jeremit0
 
Posts: n/a
Re: Need timer with ability to time long intervals and sub-second precision

On Aug 1, 11:44 am, Oncaphillis <oncaphil...@snafu.de> wrote:
> jeremit0 wrote:
> > I need a timer that has sub-second precision and can time for longer
> > than 2 hours.

>
> Hows about gettimeofday ?
>
> http://www.opengroup.org/onlinepubs/...s/gettimeofday....
>
> If your system provides it


This sounds like another good suggestion. The code does have to be
platform independent–OS X and Linux mostly–so I'll take that into
consideration. I'll take a look to see if it works for me.

Thanks,
Jeremy


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #6 (permalink)  
Old 08-20-2008, 09:58 PM
Jorgen Grahn
 
Posts: n/a
Re: Need timer with ability to time long intervals and sub-second precision

On Fri, 1 Aug 2008 18:53:15 CST, jeremit0 <jeremit0@gmail.com> wrote:

[gettimeofday(2)]

> This sounds like another good suggestion. The code does have to be
> platform independent -- OS X and Linux mostly -- so I'll take that into
> consideration.


This is slightly off-topic, but I cannot help mentioning it: OS X and
Linux are, for these purposes, the same platform. They're modern Unix
systems. You probably have no reason to worry unless you target Windows,
IBM mainframes, or exotic embedded environments.

You might want to read up a bit on Unix standards like Posix and the
Single UNIX Specification, and compare to the documentation that comes
with your systems.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > C++


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:22 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Xecuter 3 Mod Chip | Hybrid Car Rental | Loans | Credit Card | Gas Suppliers



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114