Solved

difftime() seems to have a resolution of 1 second - anything more accurate?

Posted on 2004-09-20
2
814 Views
Last Modified: 2012-05-05
Hi,

Difftime seems to have a resolution of 1 second, ie:

                              //
                              // Profiling: output time since last operation
                              //
                              {
                                    time(&profiling_now);
                                    time_t td;
                                    td=difftime(profiling_now, profiling_then);
                                    td=(float)td;
                                    my_fprintf_VL7(stderr,"[t2=%2.3fs]",td);
                                    time(&profiling_then);
                              }

... prints  things like [t2=1.000s] or [t2=3.000s].

Any calls in the Linux 2.6 kernel that can get a resolution down to 1/100 of a second? This excludes driver calls - this is an application.

Shane.
0
Comment
Question by:Risky101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 125 total points
ID: 12109178
time_t is number of seconds since 1970, so subtracting two values will give a
value with 1-second resolution.  You want to check out the gettimeofday() function,
which returns the following structure:

     struct timeval {
             long    tv_sec;         /* seconds since Jan. 1, 1970 */
             long    tv_usec;        /* and microseconds */
     };

It would be trivial to write a function that subtracts two timeval structures,
returning 1/100s of a second.

0
 
LVL 3

Expert Comment

by:scn
ID: 12111615
The macro timersub defined in sys/time.h performs substractions of timeval structure variables
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question