Google Answers Logo
View Question
 
Q: Measuring Unix gettimeofday system call resolution ( Answered,   0 Comments )
Question  
Subject: Measuring Unix gettimeofday system call resolution
Category: Computers > Operating Systems
Asked by: sivasruj-ga
List Price: $3.00
Posted: 13 May 2003 18:43 PDT
Expires: 12 Jun 2003 18:43 PDT
Question ID: 203397
I need to find the actual resolution of gettimeofday system call, on a
computer with Redhat linux operating system. I took measuremnts on a
system and want to find the accuracy of the delays given by
gettimeofday.
I know some people say gettimeofday gives 1 micro sec(us) resolution.
But it actually depends on the operating system and CPU speed etc. So
i want to know how to measure the resolution that gettimeofday is
giving me on my system.
It would be good if you can provide me with some code to do that.
Answer  
Subject: Re: Measuring Unix gettimeofday system call resolution
Answered By: eiffel-ga on 14 May 2003 04:36 PDT
 
Hi sivasruj,

The following message on the SuSE Linux list seems to be relevant.
Alex Rhomberg wrote:

"I use gettimeofday for time measurement. On my PWS500a with RH 6.1,
this works fine, giving me us resolution. A test on UP2000 with SuSE
6.1 returns the same time every time, with 1ms jumps."

Alex Rhomberg, SuSE Linux mailing list
http://lists.suse.com/archive/suse-axp/2000-Mar/0115.html

So, certainly for RedHat 6.1 he was able to get microsecond
resolution.

In that same posting, Alex Rhomberg also listed the following small C
program that he uses to measure the resolution of gettimeofday on the
RedHat and SuSE systems:

   #include <time.h> // for gettimeofday
   #include <sys/time.h>
   #include <stdio.h>
   
   int main(int argc, char**argv)
   {
     struct timeval tv1, tv2;
   
     gettimeofday(&tv1, NULL);
     do {
       gettimeofday(&tv2, NULL);
     } while (tv1.tv_usec == tv2.tv_usec);
   
     printf("Difference: %d us\n", tv2.tv_usec - tv1.tv_usec +
            1000000 * (tv2.tv_sec - tv1.tv_sec));
   
     return 0;
   }

This program should compile and run on any stock RedHat system, and
should provide the confirmation of gettimeofday resolution that you
require.


Google search strategy:

gettimeofday resolution
://www.google.com/search?q=gettimeofday%20resolution


Regards,
eiffel-ga

Request for Answer Clarification by sivasruj-ga on 14 May 2003 06:25 PDT
Hi Eiffel,

          I hope you could clarify this doubt of mine.
I am measuring some delays which are in the range of 4 - 10 us .

And if my Redhat system is giving me a resolution of 2 us , with
gettimeofday.
would it be appropriate and accurate to calculate the delays using
gettimeofday? Or do I need better resolution ? If so , how much?

Clarification of Answer by eiffel-ga on 14 May 2003 09:34 PDT
Hi sivasruj,

You haven't said how accurate your measurements need to be, so it's
not possible to say whether you need higher resolution. But a
resolution of 2 microseconds means that measurements of durations in
the range 4 to 10 microseconds will not be very precise.

If the occurrence that you are timing is repeatable, you can average a
large number of measurements to improve the effective resolution.

For example if you obtain 42 measurements of 10us and 58 measurements
of 12us, you can estimate the actual duration to be close to 11.16us.

Regards,
eiffel-ga
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy