class
<chrono>

std::chrono::steady_clock

class steady_clock;
Steady clock
Clock classes provide access to the current time_point.

steady_clock is specifically designed to calculate time intervals.

Clock properties

monotonic
Its member now never returns a lower value than in a previous call.
steady
Every tick the clock advances takes the same amount of time (in terms of physical time).

Member types

The following aliases are member types of steady_clock:

member typedefinitionnotes
repAn arithmetic type (or a class that emulates it)Used to store a count of periods.
periodA ratio typeRepresents the length of a period in seconds.
durationduration<rep,period>The clock's duration type.
time_pointtime_point<steady_clock>The clock's time_point type.

Member constants

member constantdefinition
is_steadytrue

Static member functions


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// steady_clock example
#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>

int main ()
{
  using namespace std::chrono;

  steady_clock::time_point t1 = steady_clock::now();

  std::cout << "printing out 1000 stars...\n";
  for (int i=0; i<1000; ++i) std::cout << "*";
  std::cout << std::endl;

  steady_clock::time_point t2 = steady_clock::now();

  duration<double> time_span = duration_cast<duration<double>>(t2 - t1);

  std::cout << "It took me " << time_span.count() << " seconds.";
  std::cout << std::endl;

  return 0;
}


Possible output:
printing out 1000 stars...
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
****************************************
It took me 0.112006 seconds.

See also

steady_clock