. :
<chrono>. . time_point. . <chrono> . , std::chrono, , , :: clock std::high_resolution_clock ( - ).
, :
std::cout << "seconds since start: " << ((double) difference / 1000000);
, , (, 1000000), , , chrono . , . , ?!
:
, .
chrono . , , :
typedef std::chrono::duration<double> sec;
sec difference = end - start;
std::cout << "seconds since start: " << difference.count() << '\n';
1 , .
time_point . steady_clock::time_point ( ) chrono . , :
auto difference = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()
, - .count(). , :
std::cout << "seconds since start: " << ((double) difference / 1000000);
std::chrono::steady_clock, QueryPerformanceCounter, . QueryPerformanceCounter.
<disclaimer>
Windows, .
</disclaimer>
struct my_clock
{
typedef double rep;
typedef std::ratio<1> period;
typedef std::chrono::duration<rep, period> duration;
typedef std::chrono::time_point<my_clock> time_point;
static const bool is_steady = false;
static time_point now()
{
static const long long frequency = init_frequency();
long long t;
QueryPerformanceCounter(&t);
return time_point(duration(static_cast<rep>(t)/frequency));
}
private:
static long long init_frequency()
{
long long f;
QueryPerformanceFrequency(&f);
return f;
}
};
, rep a double period 1 . rep period - , . typedef QueryPerformanceCounter duration now().
, :
int main()
{
auto start = my_clock::now();
for (unsigned long long int i = 0; i < 10000; ++i) {
std::vector<int> v(i, 1);
}
auto end = my_clock::now();
auto difference = end - start;
std::cout << "seconds since start: " << difference.count() << '\n';
}
( ) . std::chrono::steady_clock.
<chrono> . .: -)