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

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

🌸 std::chrono::file_clock::now β€” NAME 🌸

okay so bestie, this is page 3 of the C++ Standard Library manual, and today's main character is std::chrono::file_clock::now β€” yes, that's literally the whole name, it's std::chrono::file_clock::now and it's iconic for it πŸ’…


✨ Synopsis ✨

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

(since C++20)

noexcept;

So like β€” it returns a time point representing the current point in time. that's the vibe. that's the whole job 🫢


πŸŽ€ Parameters πŸŽ€

  • (none) β€” literally nothing, it takes zero arguments, no cap, it just shows up and does the thing πŸ’€

πŸ’– Return value πŸ’–

A time point representing the current time. that's it, that's the return value, she's simple and she's flawless ✨


πŸ¦‹ Example πŸ¦‹

okay so here's the demo, run this code bestie πŸ‘‘

// 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::file_clock::now();
        do_some_work(size);
        const auto end = std::chrono::file_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
ngl those numbers are just illustrative β€” "possible output" is doing a lot of heavy lifting there, so don't come for her if your laptop times things differently πŸ™ˆ

aaaaand that's the page bestie, we ate, no crumbs πŸ“ this came straight from http://cppreference.com, dated 2024.06.10, and honestly? iconic of them. periodt πŸ’œπŸ§š

πŸ“¦ where this page comes from