| 2898 | class timer { |
| 2899 | public: |
| 2900 | class entry { |
| 2901 | public: |
| 2902 | entry() {} |
| 2903 | |
| 2904 | entry(std::map<std::string, std::chrono::high_resolution_clock::time_point>::const_iterator start_it) |
| 2905 | : start_it(start_it) {} |
| 2906 | |
| 2907 | void stop() { |
| 2908 | if (start_it) { |
| 2909 | auto end = std::chrono::high_resolution_clock::now(); |
| 2910 | auto duration = std::chrono::duration<double, std::milli>(end - start_it.value()->second).count(); |
| 2911 | std::cerr << "Timing for " << start_it.value()->first << ": " << duration << " ms" << std::endl; |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | private: |
| 2916 | std::optional<std::map<std::string, std::chrono::high_resolution_clock::time_point>::const_iterator> start_it; |
| 2917 | }; |
| 2918 | |
| 2919 | timer(bool enabled = true) : enabled_(enabled) {} |
| 2920 | |