8 namespace Intel { namespace OCDemo {
12 static unsigned long long oc = 0;
16 }} // namespace Intel::OCDemo
18 // Helper for measuring call times:
19 namespace Intel { namespace OCDemo {
22 using namespace std::chrono;
24 call_times call_timer;
26 void call_times::reset(const std::string& entry)
28 timings[entry] = make_pair(high_resolution_clock::now(), std::chrono::high_resolution_clock::time_point());
31 void call_times::mark(const std::string& name)
33 auto e = timings.find(name);
35 if(timings.end() == e)
41 auto& tp = (*e).second;
43 if(tp.first > tp.second)
44 timings[name].second = high_resolution_clock::now();
47 void call_times::report()
49 cout << "Time marks:\n";
51 for_each(begin(timings), end(timings),
52 [](const std::pair<std::string, clock_interval>& tm) -> void
54 const std::string& name { tm.first };
56 const time_point<high_resolution_clock>& request_time { tm.second.first };
57 const time_point<high_resolution_clock>& response_time { tm.second.second };
59 cout << '\t' << name << ": ";
61 if(request_time > response_time)
63 cout << "<waiting>\n";
67 auto elapsed_ms = duration_cast<std::chrono::milliseconds>(response_time - request_time).count();
68 cout << elapsed_ms << "ms (";
70 auto elapsed_us = duration_cast<std::chrono::microseconds>(response_time - request_time).count();
71 cout << elapsed_us << "us)\n";
75 void call_times::report_and_reset(const std::string& name)
77 mark(name), report(), reset(name);
81 }} // namespace Intel::OCDemo