12int64_t getProcessCpuTime() {
14 FILETIME creation_time, exit_time, kernel_time, user_time;
15 GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time,
16 &kernel_time, &user_time);
17 return static_cast<int64_t
>(user_time.dwHighDateTime) << 32 |
18 user_time.dwLowDateTime;
20 struct timespec cpu_time;
21 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &cpu_time);
22 return static_cast<int64_t
>(cpu_time.tv_sec) * 1'000'000'000 +
32 using millis_f64 = std::chrono::duration<double, std::milli>;
33 auto wall_ms = millis_f64(t.
wall_time).count();
34 auto cpu_ms = millis_f64(t.
cpu_time).count();
35 auto cpu_pct = 100 * cpu_ms / wall_ms;
36 auto prec = os.precision(6);
37 os << std::setw(8) << wall_ms <<
" ms (wall) ─ "
38 << std::setw(8) << cpu_ms <<
" ms (CPU) ─ "
39 << std::setprecision(5) << std::setw(7) << cpu_pct <<
"%";
50 auto wall_end_time = clock::now();
51 auto cpu_end_time = getProcessCpuTime();
52 ++
time.num_invocations;
std::chrono::nanoseconds wall_time
std::chrono::nanoseconds cpu_time
std::ostream & operator<<(std::ostream &, TimingsCPU)
Measures the number of invocations of a specific piece of code and its run time.
clock::time_point wall_start_time
CPU and wall-time measurements with RAII helper.