Defined in header <ctime> | ||||
---|---|---|---|---|
|
Computes difference between two calendar times as std::time_t
objects (time_end - time_beg
) in seconds. If time_end
refers to time point before time_beg
then the result is negative.
Parameters
time_beg, time_end | - | times to compare |
Return value
Difference between two times in seconds.
Notes
On POSIX systems, std::time_t
is measured in seconds, and difftime
is equivalent to arithmetic subtraction, but C and C++ allow fractional units for time_t
.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> #include <ctime> int main() { std:: time_t start = std:: time (NULL); volatile double d; // some time-consuming operation for ( int n=0; n<10000; ++n) { for ( int m=0; m<100000; ++m) { d += d*n*m; } } std::cout << "Wall time passed: " << std:: difftime (std:: time (NULL), start) << " s.\n" ; } |
Output:
1 | Wall time passed: 7 s. |
See also
(C++11) | a time interval (class template) |
C documentation for difftime |
Please login to continue.