mercredi 24 mars 2021

What does std::chrono::duration::count return?

#include <iostream>
#include <chrono>


int main()
{
    std::chrono::time_point<std::chrono::system_clock> start_time, end_time;
    start_time = std::chrono::system_clock::now();
    //do something
    for (int i = 0; i<100000; ++i)
        std::cout << "";

    end_time = std::chrono::system_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
    std::cout << "\n" << duration.count();


    return 0;
}

I haven't seen it clearly in the docs, so what to check, that in this code spnippet when I got 22 printed to console it means 22 milliseconds. And if to write std::chrono::duration_cast<std::chrono::microseconds> and I receive 22323 it's microseconds, and so on. Correct?

Aucun commentaire:

Enregistrer un commentaire