Calico
A visual-inertial calibration library designed for rapid problem construction and debugging.
profiler.h
1 #ifndef CALICO_PROFILER_H_
2 #define CALICO_PROFILER_H_
3 
4 #include <chrono>
5 #include <iostream>
6 
7 #include "absl/strings/str_format.h"
8 #include "absl/strings/string_view.h"
9 
10 
11 namespace calico {
12 
13 class Profiler {
14  public:
15  Profiler() {
16  Tic();
17  }
18 
19  void Tic() {
20  stamp_prev_ = std::chrono::high_resolution_clock::now();
21  }
22 
23  double Toc(absl::string_view msg = "") {
24  const auto stamp = std::chrono::high_resolution_clock::now();
25  const auto dt_nanos =
26  std::chrono::duration_cast<std::chrono::nanoseconds>(
27  stamp - stamp_prev_).count();
28  const double dt = static_cast<double>(dt_nanos) * 1.0e-9;
29  if (!msg.empty()) {
30  std::cout << absl::StrFormat("Elapsed time: %.9fs - %s", dt, msg)
31  << std::endl;
32  }
33  return dt;
34  }
35 
36  private:
37  std::chrono::high_resolution_clock::time_point stamp_prev_;
38 };
39 
40 } // namespace calico
41 
42 #endif //CALICO_PROFILER_H_
Definition: profiler.h:13
Primary calico namespace.
Definition: __init__.py:1