Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

20 Experts available now in Live!

Get 1:1 Help Now