std::chrono..._clock::now(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

okay so bestie, welcome to the std::chrono..._clock::now(3) page from the C++ Standard Libary (yes, that spelling is on the page, iykyk πŸ‘€). This one is short and iconic:

  • std::chrono::steady_clock::now - std::chrono::steady_clock::now β€” literally the same name on both sides, and that's the whole NAME section, periodt πŸ’…

πŸ¦‹ Synopsis πŸ¦‹

Here's the signature, copied exactly:

static std::chrono::time_point<std::chrono::steady_clock> now()

(since C++11)

noexcept;

It returns a time point representing the current point in time. That's the whole vibe ✨


✨ Parameters ✨

(none) β€” yes bestie, zero params, not a single one 🫢


πŸŽ€ Return value πŸŽ€

A time point representing the current time. That's the tea πŸ’…


🌸 Example 🌸

// Run this code β€” and here's the code, with all the tokens kept exactly:

// Run this code

#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::steady_clock::now();
        do_some_work(size);
        const auto end = std::chrono::steady_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

mwah πŸ’‹ β€” cute little sign-off for the footer info: source is http://cppreference.com, version/date is 2024.06.10, and the page is std::chrono..._clock::now(3). bye bestie, go vibe with your clocks 🫢✨

πŸ“¦ where this page comes from