Solved

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

Posted on 2004-09-20
2
783 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now