1 #ifndef VTESTBED_PROFILE_PROFILE_HH 2 #define VTESTBED_PROFILE_PROFILE_HH 4 #include <vtestbed/config/profile.hh> 6 #if defined(VTB_WITH_PROFILE) 20 extern thread_local
int profile_level;
22 extern const char* filename;
25 template <
class Tuple, std::
size_t N>
29 out <<
' ' << std::get<N-1>(t);
33 template <
class Tuple>
35 static void print(
std::ostream& out,
const Tuple& t) { out << std::get<0>(t); }
55 using time_point = clock::time_point;
56 using duration = clock::duration;
59 const char* _tag =
"";
60 time_point _t0{duration::zero()};
61 time_point _t1{duration::zero()};
72 _t1{duration::zero()},
73 _level{++profile_level}
83 template <
class ... Args>
88 using time_point = clock::time_point;
89 using duration = clock::duration;
94 const char* _tag =
"";
95 time_point _t0{duration::zero()};
96 time_point _t1{duration::zero()};
103 inline explicit Benchmark(
const char* tag, Args... params):
104 _tag{tag}, _t0{
clock::now()}, _t1{duration::zero()}, _params{params...} {}
107 using namespace std::chrono;
109 auto dt = duration_cast<microseconds>(this->_t1 - this->_t0);
112 if (!stream.is_open()) { stream.open(filename); }
113 stream << this->_tag <<
' ';
114 traits_type::print(stream,this->_params);
115 stream <<
' ' << dt.count() << std::endl;
122 template <
class ... Args>
124 make_benchmark(
const char* tag, Args... args) {
132 #define VTB_PROFILE_BLOCK(tag) \ 133 ::vtb::profile::Profile __profile_ ## __LINE__{tag} 135 #define VTB_BENCHMARK_BLOCK(tag, ...) \ 136 auto __benchmark_ ## __LINE__ = ::vtb::profile::make_benchmark(tag,__VA_ARGS__) 140 #define VTB_PROFILE_BLOCK(tag) 141 #define VTB_BENCHMARK_BLOCK(tag, ...) 145 #endif // vim:filetype=cpp Record code block execution time.