Chrono library is used to deal with date and time. This library was designed to deal with the fact that timers and clocks might be different on different systems and thus to improve over time in terms of precision. The unique thing about chrono is that it provides a precision-neutral concept by separating duration and point of time (“timepoint”) from specific clocks.
chrono is the name of a header and also of a sub-namespace: All the elements in this header (except for the common_type specializations) are not defined directly under the std namespace (like most of the standard library) but under the std::chrono namespace.
The elements in this header deal with time. This is done mainly by means of three concepts:
A duration object expresses a time span by means of a count like a minute, two hours, or ten milliseconds. For example, “42 seconds” could be represented by a duration consisting of 42 ticks of a 1-second time unit.
duration (in periods): 60000 milliseconds. duration (in seconds): 60 seconds.
A clock consists of a starting point (or epoch) and a tick rate. For example, a clock may have an epoch of February 22, 1996 and tick every second. C++ defines three clock types:
- system_clock-It is the current time according to the system (regular clock which we see on the toolbar of the computer). It is written as- std::chrono::system_clock
- steady_clock-It is a monotonic clock that will never be adjusted.It goes at a uniform rate. It is written as- std::chrono::steady_clock
- high_resolution_clock– It provides the smallest possible tick period. It is written as-std::chrono::high_resolution_clock
A time_point object expresses a point in time relative to a clock’s epoch. Internally, the object stores an object of a duration type, and uses the Clock type as a reference for its epoch.
f(42) = 267914296 finished computation at Wed Jan 4 05:13:48 2017 elapsed time: 2.14538s
This article is contributed by Shambhavi Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- History of C++
- What are Forward declarations in C++
- __builtin_inf() functions of GCC compiler
- Structures in C++
- Variables in C++
- Implementing Forward Iterator in BST
- Count substrings that contain all vowels | SET 2
- Machine Learning in C++
- How can we use Comma operator in place of curly braces?
- Optimally accommodate 0s and 1s from a Binary String into K buckets
- Find a number containing N - 1 set bits at even positions from the right
- Sort an array according to absolute difference with given value using Functors
- Rearrange characters in a string such that no two adjacent are same using hashing
- Remove duplicate elements in an Array using STL in C++