![]() |
|
|
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. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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! ] |
|
|||
|
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! ] |
|
|||
|
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! ] |
|
|||
|
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! ] |
|
|||
|
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! ] |
|
|||
|
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! ] |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|