Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions geode/utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ set(module_HEADERS
stream.h
str.h
time.h
timed_call.h
tr1.h
type_traits.h
Unique.h
Expand Down
25 changes: 25 additions & 0 deletions geode/utility/timed_call.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include <geode/utility/time.h>
namespace geode {

struct TimedCallHelper {
std::string msg;
real start_time = get_time();
TimedCallHelper(const string& new_msg)
: msg(new_msg)
{ }
~TimedCallHelper() {
const auto end_time = get_time();
std::cout << msg << " took " << (end_time - start_time) << " seconds.\n";
}
};

template<class Fn, class... Args> auto timed_call(const string& msg, Fn&& fn, Args&&... args) -> decltype(fn(std::forward<Args>(args)...)) {
GEODE_UNUSED const auto& helper = TimedCallHelper{msg};
return fn(std::forward<Args>(args)...);
}

// Call a function printing execution time to cout
#define GEODE_TIMED_CALL(fn,...) geode::timed_call(#fn,fn,__VA_ARGS__)

} // geode namespace