std::chrono...i_clock::now(3)
π NAME π
std::chrono::tai_clock::now β okay so this is the manpage for std::chrono::tai_clock::now, bestie. That's it, that's the name section, we love a self-titled icon π (it's from the C++ Standard Library manual, section 3, in case you were wondering π«Ά).
β¨ Synopsis β¨
static std::chrono::time_point<std::chrono::tai_clock> now(); (since C++20)
So real talk: this bad boy hands you back a time point that represents the current point in time. Like, right now. Currently. As of this exact moment π .
The way it works is it's calculated as if by this call:
std::chrono::tai_clock::from_utc(std::chrono::utc_clock::now())
But β and this is the tea π΅ β implementations are allowed to use a more accurate value of TAI time if they've got one. So it's giving "at least this good, maybe better," no cap.
π Parameters π
(none) β literally zero arguments, she takes nothing, she just is β¨. The easiest function call of your entire life, you're welcome.
πΈ Return value πΈ
A time point representing the current time π. That's the whole vibe. You asked for now, you got now.
π¦ Example π¦
Okay this example is adorable, it's just timing how long it takes to fill and iterate a vector of ints, at increasing sizes. Run this code, bestie:
#include <chrono>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
volatile int sink;
void do_some_work(std::size_t size)
{
std::vector<int> v(size, 42);
sink = std::accumulate(v.begin(), v.end(), 0); // make sure it is a side effect
}
int main()
{
std::cout << std::fixed << std::setprecision(9) << std::left;
for (auto size{1ull}; size < 10'00'00'00'00ull; size *= 100)
{
const auto start = std::chrono::tai_clock::now();
do_some_work(size);
const auto end = std::chrono::tai_clock::now();
const std::chrono::duration<double> diff = end - start;
std::cout << "Time to fill and iterate a vector of " << std::setw(9)
<< size << " ints : " << diff << '\n';
}
}
Possible output:
Time to fill and iterate a vector of 1 ints : 0.000006568s
Time to fill and iterate a vector of 100 ints : 0.000002854s
Time to fill and iterate a vector of 10000 ints : 0.000116290s
Time to fill and iterate a vector of 1000000 ints : 0.011742752s
Time to fill and iterate a vector of 100000000 ints : 0.505534949s
Look at that progression π the 1 int case is literally free and the 100000000 case is out here taking half a second. volatile int sink is the real MVP though β she exists purely so the optimizer can't just delete all your hard work, periodt π₯.
Heads up: that output is possible output, not promised output β your machine is gonna do its own thing, and that's fine π.
Okay that's the whole page, you're officially educated π§ Go forth and timestamp things. Sending you good vibes and no utc_clock regressions β this was std::chrono...i_clock::now(3) from the C++ Standard Libary manual, straight off http://cppreference.com, dated 2024.06.10 πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms