std::chrono...n_clock::now(3)
π NAME π
std::chrono::high_resolution_clock::now β and yeah, the man page literally lists std::chrono::high_resolution_clock::now a second time right after the dash, no extra sauce, that's just how she filed herself. Periodt.
This page lives in the C++ Standard Libary (yes "Libary", the typo is canon, I don't make the rules π), section 3 of the manual β and the header at the top of the page is genuinely truncated into std::chrono...n_clock::now(3) because the title got cut off mid-word. Iconic behavior, honestly. Anyway. Bestie. It's a clock. It tells you now. Let's go π
β¨ Synopsis β¨
The man page formatting did us SO dirty here, so here's exactly what got printed on the page, verbatim, scrambled eggs and all π:
static std::chrono::time_point<std::chrono::high_resolution_clock>
now() (since
noexcept;
C++11)
...and here's the same thing un-scrambled so your brain can vibe check it π«Ά:
static std::chrono::time_point<std::chrono::high_resolution_clock> now() noexcept;
(since C++11)
π§ what that actually means, lowkey
staticβ it's a static member function, so no object needed. You don't instantiate anything, you just call it.std::chrono::time_point<std::chrono::high_resolution_clock>β that's the return type, a whole time point parameterized on the high resolution clock.now()β the function name. No arguments.noexceptβ it's promising not to throw. A well-behaved queen.(since C++11)β she's been around since C++11. An elder icon.
Heads up: that's the entire synopsis. No overloads hiding in the back, no secret extra params. Just now().
πΈ Description πΈ
Returns a time point representing the current point in time. That's it. That's the whole job π
π¦ Parameters π¦
(none) β literally zero arguments. Nada. She takes nothing, she needs nothing, she simply knows what time it is.
β Return value β
A time point representing the current time. Slay π
π₯ Example π₯
The page says // Run this code, so here's the code, exactly as it appears, bestie β don't let the wrapped lines jump-scare you, that's just the man page being narrow:
#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::high_resolution_clock::now();
do_some_work(size);
const auto end = std::chrono::high_resolution_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 π
Note the word possible β this is one run, not a promise, your numbers may lowkey differ:
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
And that's the whole page, bestie π«Ά No SEE ALSO, no bugs section, no author credits β she's short and she knows it.
Cute little sign-off for the record: this page came from http://cppreference.com, dated 2024.06.10, and it's filed under std::chrono...n_clock::now(3) β same truncated-name situation as the header. Bye bye, go time something, I'm obsessed with you getting it right πβ±οΈ
π¦ 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