Skip to contentSkip to conversation

Measure time

DISCUSSION Serguei I. Ivantsov 8 participants 11 messages May 8, 2002

lore
Share & tools
lore
#0 lore raw

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

--
Regards,
Serguei I. Ivantsov
GSC Game World

#1 lore raw
Quoted 5 lines

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

you can directly read the TSC but that will not realy give you nanoseconds resolution as the actual read access even on a PIII/1GHz is going to take up to a few 100 nanoseconds, and depending on what you want to time stamp the overall jitter of that code can easaly be in the range of a microsecond.

There are some hard-realtime patches to the Linux kernel that will allow time precission of aprox. 1us (the TSC has a precission of 32ns) but I don't think you can get below that without dedicated hardware.

for RTLinux check at ftp://ftp.rtlinux.org/pub/rtlinux/

hofrat

#10 lore raw
In reply to Serguei I. Ivantsov
Quoted 10 lines · Serguei I. Ivantsov

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

--
Regards,
Serguei I. Ivantsov
GSC Game World

gettimeofday() returns seconds/microseconds. If you need nanoseconds, you can read CPU clock cycles in Intel machines with (assembly) rdtsc instructions and convert, based upon the CPU clock.

If you really need nanosecond resolution in code that may be interrupted or preempted at any time, you are in a world of hurt. I suggest you review the requirement. You may need a TMS320C30 or similar DSP standing alone.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).

Windows-2000/Professional isn't.

#2 lore raw
In reply to Der Herr Hofrat

Is there any function like GetTickCount() in M$ Win32 that retrieves time in milliseconds?

--
Regards,
Serguei I. Ivantsov

----- Original Message -----
From: "Der Herr Hofrat" <[email protected]>
To: "Serguei I. Ivantsov" <[email protected]>
Cc: <[email protected]>; <[email protected]>
Sent: Wednesday, May 08, 2002 3:00 PM
Subject: Re: Measure time

Quoted 18 lines
Quoted 5 lines

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

you can directly read the TSC but that will not realy give you nanoseconds resolution as the actual read access even on a PIII/1GHz is going to take up to a few 100 nanoseconds, and depending on what you want to time stamp the overall jitter of that code can easaly be in the range of a microsecond.

There are some hard-realtime patches to the Linux kernel that will allow time precission of aprox. 1us (the TSC has a precission of 32ns) but I don't think you can get below that without dedicated hardware.

for RTLinux check at ftp://ftp.rtlinux.org/pub/rtlinux/

hofrat

#3 lore raw

With you can get system time and then use the millisecond member in Win32...

<code>

SYSTEMTIME systm;

GetSystemTime(&systm);

/*
Can access members of the structure

systm.wMilliseconds
systm.wSecond
systm.wMinute
systm.wHour

... and yet more members ...
*/

</code>

~ Nate

----- Original Message -----
From: "Serguei I. Ivantsov" <[email protected]>
To: "Der Herr Hofrat" <[email protected]>
Cc: <[email protected]>; <[email protected]>
Sent: Wednesday, May 08, 2002 8:46 AM
Subject: Re: Measure time

Quoted 1 line

Is there any function like GetTickCount() in M$ Win32 that retrieves time

in

Quoted 6 lines

milliseconds?

--
Regards,
Serguei I. Ivantsov

Quoted 14 lines

----- Original Message -----
From: "Der Herr Hofrat" <[email protected]>
To: "Serguei I. Ivantsov" <[email protected]>
Cc: <[email protected]>; <[email protected]>
Sent: Wednesday, May 08, 2002 3:00 PM
Subject: Re: Measure time

Quoted 6 lines
Quoted 5 lines

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

you can directly read the TSC but that will not realy give you

nanoseconds

Quoted 1 line
Quoted 1 line

resolution as the actual read access even on a PIII/1GHz is going to

take

Quoted 17 lines
Quoted 11 lines

up to a few 100 nanoseconds, and depending on what you want to time stamp the overall jitter of that code can easaly be in the range of a microsecond.

There are some hard-realtime patches to the Linux kernel that will allow time precission of aprox. 1us (the TSC has a precission of 32ns) but I don't think you can get below that without dedicated hardware.

for RTLinux check at ftp://ftp.rtlinux.org/pub/rtlinux/

hofrat

-
To unsubscribe from this list: send the line "unsubscribe linux-gcc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
In reply to Der Herr Hofrat
Quoted 11 lines · Der Herr Hofrat
Quoted 5 lines

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

you can directly read the TSC but that will not realy give you nanoseconds resolution as the actual read access even on a PIII/1GHz is going to take up to a few 100 nanoseconds, and depending on what you want to time stamp the overall jitter of that code can easaly be in the range of a microsecond.

Quoted 5 lines

There are some hard-realtime patches to the Linux kernel that will allow time precission of aprox. 1us (the TSC has a precission of 32ns) but I don't think you can get below that without dedicated hardware.

for RTLinux check at ftp://ftp.rtlinux.org/pub/rtlinux/

I recommend RTAI instead. It's more feature-rich, and works with newer kernels.. the url is http://www.aero.polimi.it/~rtai/, or
http://www.rtai.org.

-Calin

Quoted 8 lines

hofrat
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
In reply to Serguei I. Ivantsov
Quoted 3 lines · Serguei I. Ivantsov

Is there any function like GetTickCount() in M$ Win32 that retrieves time in milliseconds?

The kernel provides gettimeofday() which give micro seconds AND is usually quite accurate. On machines of about 800 MHZ and better you can, sometimes, even get the same value on back to back readings.

The high-res-timers patch (see sig. below) implements the POSIX clocks and timers which return values in nanoseconds, but the resolution, due to jitter and such is still in the range of micro seconds.

If, on the other hand, you are trying to measure execution time of some task that blocks during that time, you are in a world of hurt. The kernel allocates 1/HZ chunks of elapsed time to what ever task it finds running at the 1/HZ tick. There is NO attempt by the kernel to refine this measurement.

George

Quoted 36 lines

--
Regards,
Serguei I. Ivantsov

----- Original Message -----
From: "Der Herr Hofrat" <[email protected]>
To: "Serguei I. Ivantsov" <[email protected]>
Cc: <[email protected]>; <[email protected]>
Sent: Wednesday, May 08, 2002 3:00 PM
Subject: Re: Measure time

Quoted 11 lines
Quoted 5 lines

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

you can directly read the TSC but that will not realy give you nanoseconds resolution as the actual read access even on a PIII/1GHz is going to take up to a few 100 nanoseconds, and depending on what you want to time stamp the overall jitter of that code can easaly be in the range of a microsecond.

Quoted 7 lines

There are some hard-realtime patches to the Linux kernel that will allow time precission of aprox. 1us (the TSC has a precission of 32ns) but I don't think you can get below that without dedicated hardware.

for RTLinux check at ftp://ftp.rtlinux.org/pub/rtlinux/

hofrat

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 4 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Real time sched:  http://sourceforge.net/projects/rtsched/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#9 lore raw
In reply to Der Herr Hofrat
Quoted 3 lines · Serguei I. Ivantsov

Is there any function like GetTickCount() in M$ Win32 that retrieves time in milliseconds?

The kernel provides gettimeofday() which give micro seconds AND is usually quite accurate. On machines of about 800 MHZ and better you can, sometimes, even get the same value on back to back readings.

The high-res-timers patch (see sig. below) implements the POSIX clocks and timers which return values in nanoseconds, but the resolution, due to jitter and such is still in the range of micro seconds.

If, on the other hand, you are trying to measure execution time of some task that blocks during that time, you are in a world of hurt. The kernel allocates 1/HZ chunks of elapsed time to what ever task it finds running at the 1/HZ tick. There is NO attempt by the kernel to refine this measurement.

George

Quoted 36 lines

--
Regards,
Serguei I. Ivantsov

----- Original Message -----
From: "Der Herr Hofrat" <[email protected]>
To: "Serguei I. Ivantsov" <[email protected]>
Cc: <[email protected]>; <[email protected]>
Sent: Wednesday, May 08, 2002 3:00 PM
Subject: Re: Measure time

Quoted 11 lines
Quoted 5 lines

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

you can directly read the TSC but that will not realy give you nanoseconds resolution as the actual read access even on a PIII/1GHz is going to take up to a few 100 nanoseconds, and depending on what you want to time stamp the overall jitter of that code can easaly be in the range of a microsecond.

Quoted 7 lines

There are some hard-realtime patches to the Linux kernel that will allow time precission of aprox. 1us (the TSC has a precission of 32ns) but I don't think you can get below that without dedicated hardware.

for RTLinux check at ftp://ftp.rtlinux.org/pub/rtlinux/

hofrat

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 4 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Real time sched:  http://sourceforge.net/projects/rtsched/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#5 lore raw
In reply to Serguei I. Ivantsov

Hi,

ftime() will return milliseconds, but it's considered an obsolete function. You could use gettimeofday() (as Richard Johnson suggested) to get microseconds and divide them to get milliseconds, although I don't know how time critical your routines are.

If you're still looking for nanoseconds, I'm told you can use clock_gettime() but it's still quite unavailable (I've never seen it myself, yet).. however even if it was available you possibly wouldn't get a very high resolution from it with current systems..

- Simon

Quoted 52 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Serguei I. Ivantsov
Sent: Thursday, 9 May 2002 01:47
To: Der Herr Hofrat
Cc: [email protected]; [email protected]
Subject: Re: Measure time

Is there any function like GetTickCount() in M$ Win32 that retrieves time in
milliseconds?

--
Regards,
Serguei I. Ivantsov

----- Original Message -----
From: "Der Herr Hofrat" <[email protected]>
To: "Serguei I. Ivantsov" <[email protected]>
Cc: <[email protected]>; <[email protected]>
Sent: Wednesday, May 08, 2002 3:00 PM
Subject: Re: Measure time

Quoted 6 lines
Quoted 5 lines

Hello!

Is there any function for high precision time measuring. time() returns only in second. I need nanoseconds.

you can directly read the TSC but that will not realy give you

nanoseconds

Quoted 1 line

resolution as the actual read access even on a PIII/1GHz is

going to take

Quoted 11 lines

up to a few 100 nanoseconds, and depending on what you want to time stamp the overall jitter of that code can easaly be in the range of a microsecond.

There are some hard-realtime patches to the Linux kernel that will allow time precission of aprox. 1us (the TSC has a precission of 32ns) but I don't think you can get below that without dedicated hardware.

for RTLinux check at ftp://ftp.rtlinux.org/pub/rtlinux/

hofrat

-
To unsubscribe from this list: send the line "unsubscribe linux-gcc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 8 lines

Hi,

ftime() will return milliseconds, but it's considered an obsolete function. You could use gettimeofday() (as Richard Johnson suggested) to get microseconds and divide them to get milliseconds, although I don't know how time critical your routines are.

Quoted 5 lines

If you're still looking for nanoseconds, I'm told you can use clock_gettime() but it's still quite unavailable (I've never seen it myself, yet).. however even if it was available you possibly wouldn't get a very high resolution from it with current systems..

clock_gettime() is available in the hard realtime extensions like RTLinux . The clock resolution is limited to 32ns though - and atleast on X86 I don't think there is a way to get below that.

hofrat

#7 lore raw
Quoted 9 lines · Der Herr Hofrat
Quoted 9 lines

Hi,

ftime() will return milliseconds, but it's considered an obsolete function. You could use gettimeofday() (as Richard Johnson suggested) to get microseconds and divide them to get milliseconds, although I don't know how time critical your routines are.

Quoted 8 lines
Quoted 5 lines

If you're still looking for nanoseconds, I'm told you can use clock_gettime() but it's still quite unavailable (I've never seen it myself, yet).. however even if it was available you possibly wouldn't get a very high resolution from it with current systems..

clock_gettime() is available in the hard realtime extensions like RTLinux . The clock resolution is limited to 32ns though - and atleast on X86 I don't think there is a way to get below that.

The high-res-timers patch provides clock_gettime() with resolution to the TSC increment. But you need to understand that this is a system call which can take on the order of 1000 or these units. Add in a little cach hit/ miss and interrupt randomness and well...

Still, there it is. Check out the web site below.

Signature · 4 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Real time sched:  http://sourceforge.net/projects/rtsched/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml