diff --git a/include/teqp/types.hpp b/include/teqp/types.hpp index a9644a9fba018719ce5d850647ebe1f9d7d2debd..e84f21d80bc74268698862176ec4552bae12cb5f 100644 --- a/include/teqp/types.hpp +++ b/include/teqp/types.hpp @@ -5,6 +5,7 @@ #include <vector> #include <valarray> #include <set> +#include <chrono> // Registration of types that are considered to be containers // See https://stackoverflow.com/a/12045843 @@ -57,3 +58,15 @@ auto all_same_length = [](const nlohmann::json& j, const std::vector<std::string for (auto k : ks) { lengths.insert(j[k].size()); } return lengths.size() == 1; }; + +class Timer { +private: + int N; + decltype(std::chrono::steady_clock::now()) tic; +public: + Timer(int N) : N(N), tic(std::chrono::steady_clock::now()) {} + ~Timer() { + auto elap = std::chrono::duration<double>(std::chrono::steady_clock::now() - tic).count(); + std::cout << elap / N * 1e6 << " us/call" << std::endl; + } +}; \ No newline at end of file