[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 847
  • Last Modified:

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

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
Risky101
Asked:
Risky101
1 Solution
 
brettmjohnsonCommented:
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
 
scnCommented:
The macro timersub defined in sys/time.h performs substractions of timeval structure variables
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now