14 void start(
const std::string& section) { start_times[section] = std::chrono::high_resolution_clock::now(); }
16 void start(
const std::string& section,
const long long section_flops) {
17 start_times[section] = std::chrono::high_resolution_clock::now();
18 if (flops.count(section) == 0)
19 flops[section] = section_flops;
21 flops[section] += section_flops;
31 void stop(
const std::string& section) {
32 auto end_time = std::chrono::high_resolution_clock::now();
33 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_times[section]).count();
34 durations[section] += duration;
38 void report_internal()
const {
40 for (
const auto& entry : durations) {
42 std::cout << entry.first +
", ";
43 float s = (float)(entry.second) / 1000000;
44 float ts = (float)counts.at(entry.first);
45 printf(
"Total time: %.1f s, %.1f ms/token, %.1f token/s, %d tokens\n\n", s, s / ts * 1000, ts / s,
46 counts.at(entry.first));
49 std::cout <<
"Section, Total time(us), Average time(us), Count, GOPs:" << std::endl;
50 for (
const auto& entry : durations) {
52 row += entry.first +
", ";
53 row += std::to_string(entry.second) +
", ";
54 row += std::to_string(entry.second / counts.at(entry.first)) +
", ";
55 if (flops.count(entry.first) == 0)
56 row += std::to_string(counts.at(entry.first)) +
", N/A";
58 row += std::to_string(counts.at(entry.first)) +
", ";
60 row += std::to_string((((
float)flops.at(entry.first)) / (
float)(entry.second)) / 1000.0);
62 std::cout << row << std::endl;
78 std::map<std::string, std::chrono::high_resolution_clock::time_point> start_times;
79 std::map<std::string, long long> flops;
80 std::map<std::string, long long> durations;
81 std::map<std::string, int> counts;