in C gettimeofday() function gives time in micro second precision.
Similarly is there is any function in c for pico or nano second precision..
pls reply me as soon as possible...
Thanks in advance
in C gettimeofday() function gives time in micro second precision.
Similarly is there is any function in c for pico or nano second precision..
pls reply me as soon as possible...
Thanks in advance
gethrtime() might do what you want, but it doesn't give you the current date and time, it can only be used to measure the *length* of time between two events (such as measuring how long a for loop takes as an example)
QuantumPete
"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd
Thanks... But any other functions to do same?
Last edited by msenthil; 08-31-2007 at 01:53 AM.
1GHz == 1nS per oscillation (what speed is your machine running at BTW).
Also, light travels about 30cm in 1nS (in a vacuum).
What could you possibly be measuring which requires pico second (which is 1000 times faster than nano) precision?
This is like measuring the speed of a bullet with a sundial!
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Like Salem says, there's no way you can measure something in less than few nanoseconds precision without some extra hardware (and I'm not at all sure you can actually get anything that gets to picoseconds).
If it's a modern x86 (AMD or Intel) processor, there will be a "timestampcounter" (TSC) register, whcih is a 64-bit register that counts clock-cycles. It is counting at the speed of the processor clock in most systems - more recent processors have or have plans for a constant frequency TSC, where the TSC runs at, say, 2GHz, no matter what speed the processor actually runs at (one of the big problems with TSC is that it varies when the processor is put in slow-frequency mode to save power - PowerNow/Cool'n'Quiet/SpeedStep technologies).
For short periods of time, the TSC should be fine - there is some latency involved, and it's not a synchronizing instruction in itself - that means that the RDTSC instruction can be executed "out of order", meaning that if you have a sequence that ENDS with RDTSC, there's no guarantee that the whole sequence is finished before the RDTSC is actually performed by the processor.
--
Mats