performance/ocw/profiling/time_the_clock.cc

24 lines
665 B
C++

#include <chrono>
#include <iostream>
#include <print>
using namespace std;
constexpr static size_t TRIALS = 100000;
int main() {
chrono::microseconds diffs_ms{0};
for (size_t loop_var = 1; loop_var <= TRIALS; ++loop_var) {
auto t1 = chrono::high_resolution_clock::now();
auto t2 = chrono::high_resolution_clock::now();
diffs_ms += chrono::duration_cast<chrono::microseconds>(t2 - t1);
}
print("measuring the clock in c++ 23 {} trials had an average time duration "
"of: {} microseconds, or {} milliseconds",
TRIALS, diffs_ms / TRIALS,
chrono::duration_cast<chrono::milliseconds>(diffs_ms / TRIALS));
return 0;
}