GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::difftime(3) C++ Standard Libary std::difftime(3)

std::difftime - std::difftime


Defined in header <ctime>
double difftime( std::time_t time_end, std::time_t time_beg );


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.


time_beg, time_end - times to compare


Difference between two times in seconds.


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.

// Run this code


#include <iostream>
#include <ctime>


int main()
{
std::time_t start = std::time(nullptr);
volatile double d = 1.0;


// some time-consuming operation
for (int p=0; p<10000; ++p) {
for (int q=0; q<100000; ++q) {
d = d+p*d*q+d;
}
}


std::cout << "Wall time passed: "
<< std::difftime(std::time(nullptr), start) << " s.\n";
}


Wall time passed: 9 s.


duration a time interval
(C++11) (class template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.