Unix Programming - Getting system time with hight precision

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2007 > Getting system time with hight precision





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Getting system time with hight precision
Leigh Sharpe

2007-03-26, 1:36 am

Hi all,
Is there any way of getting the system time, right down to the microsecond,
or even millisecond?

I need to do something a little like this:

int start_time=getTheTimeSomehow(); // Get the current time
doSomethingElse(); // Go and do something
else.
int end_time=getTheTimeSomehow() // What's the time now?
int elapsed_time=end_time-start_time; // How long did it take?

And I need to know the time as accurately as possible.


I would expect there to be a function somewhere, but I just don't know
where.



Logan Shaw

2007-03-26, 1:36 am

Leigh Sharpe wrote:
> Is there any way of getting the system time, right down to the microsecond,
> or even millisecond?


gettimeofday() is one such method.

- Logan
FrenKy

2007-03-26, 8:20 am

Leigh Sharpe wrote:
> Hi all,
> Is there any way of getting the system time, right down to the microsecond,
> or even millisecond?
>
> I need to do something a little like this:
>
> int start_time=getTheTimeSomehow(); // Get the current time
> doSomethingElse(); // Go and do something
> else.
> int end_time=getTheTimeSomehow() // What's the time now?
> int elapsed_time=end_time-start_time; // How long did it take?
>
> And I need to know the time as accurately as possible.
>
>
> I would expect there to be a function somewhere, but I just don't know
> where.
>
>
>


gettimeofday()?
the_edge123.nospam@club-internet.fr

2007-03-26, 8:20 am

On 26 mar, 08:30, Logan Shaw <lshaw-use...@austin.rr.com> wrote:
> Leigh Sharpe wrote:
>
> gettimeofday() is one such method.
>
> - Logan

clock_gettime is intended to go down to the nanoseconds.

Frank Cusack

2007-03-26, 8:20 am

On Mon, 26 Mar 2007 15:40:04 +1000 "Leigh Sharpe" <lsharpe@pacificwireless.com.au> wrote:
> And I need to know the time as accurately as possible.


gethrtime() on Solaris. clock_gettime() on others.
-frank
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com