File: auto_cpu_timer.hpp

package info (click to toggle)
mapbox-variant 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,648 kB
  • sloc: cpp: 31,068; ansic: 959; python: 424; makefile: 145; objc: 59; sh: 36
file content (16 lines) | stat: -rw-r--r-- 506 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#pragma once

#include <chrono>
#include <iostream>

struct auto_cpu_timer {
    std::chrono::time_point<std::chrono::high_resolution_clock> start;
    auto_cpu_timer() : start(std::chrono::high_resolution_clock::now()) {
    }
    ~auto_cpu_timer() {
        auto end = std::chrono::high_resolution_clock::now();
        std::chrono::microseconds elapsed =
            std::chrono::duration_cast<std::chrono::microseconds>(end - start);
        std::cerr << elapsed.count() << "us" << std::endl;
    }
};