|
|
|
@ -4,31 +4,32 @@
|
|
|
|
#include <string_view>
|
|
|
|
#include <string_view>
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
namespace cb::time {
|
|
|
|
namespace cb {
|
|
|
|
|
|
|
|
|
|
|
|
time_point chrono_now() {
|
|
|
|
time::time_point time::chrono_now() {
|
|
|
|
return internal_clock::now();
|
|
|
|
return internal_clock::now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void start_measure(const std::string_view &id) {
|
|
|
|
void time::start_measure(const std::string_view &id) {
|
|
|
|
_name_to_measurement.insert({id, chrono_now()});
|
|
|
|
_name_to_measurement.insert({id, chrono_now()});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long long get_duration(const std::string_view &id) {
|
|
|
|
long long time::get_duration(const std::string_view &id) {
|
|
|
|
if (!has_measurement(id)) {
|
|
|
|
if (!has_measurement(id)) {
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (chrono_now() - _name_to_measurement.at(id)).count();
|
|
|
|
return (chrono_now() - _name_to_measurement.at(id)).count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool has_measurement(const std::string_view &id) {
|
|
|
|
bool time::has_measurement(const std::string_view &id) {
|
|
|
|
return _name_to_measurement.contains(id);
|
|
|
|
return _name_to_measurement.contains(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void measure(const std::string_view &id) {
|
|
|
|
void time::measure(const std::string_view &id) {
|
|
|
|
std::cout << "measurement: " << id << " took: " << get_duration(id) << "\n";
|
|
|
|
std::cout << "measurement: " << id << " took: " << get_duration(id) << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const time_point_map &get_measurements() {
|
|
|
|
|
|
|
|
|
|
|
|
const time::time_point_map &time::get_measurements() {
|
|
|
|
return _name_to_measurement;
|
|
|
|
return _name_to_measurement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|