Skip to content

Commit

Permalink
Add util function TimedInvoke to measure execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
vs9h committed Feb 24, 2024
1 parent 8410e1a commit 00fc369
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/util/timed_invoke.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <chrono>
#include <functional>
#include <utility>

namespace util {
/// invoke and return the time taken for execution
template <typename... Ts>
size_t TimedInvoke(Ts&&... invoke_args) {
auto const start = std::chrono::system_clock::now();
std::invoke(std::forward<Ts>(invoke_args)...);
auto const end = std::chrono::system_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
}
} // namespace util

0 comments on commit 00fc369

Please sign in to comment.