I was wondering if it's a good practice to insert performance test and measurment in the test phase of the build for a c++ project.
In my project I have some methods for which I have some execution time constraint, and my current implementation is good enough to respect them. I have some unit test implemented with gtest for those methods. I would like to take advantage of them to test that in future updates of my implementation I won't introduce some unintentional drops in performance.
Is something like this the right way to go?
auto start = std::chrono::high_resolution_clock::now().time_since_epoch().count();
some_task();
auto end = std::chrono::high_resolution_clock::now().time_since_epoch().count();
EXPECT_LT((end-start), SOME_TASK_TIME_TRHESHOLD)
Or there are some well known alternatives/libraries to implement these kind of performance checks?
high_resolution_clock
for timing. It is too weakly specified and you may, in the name of higher resolution, get a non-monotonic clock. More information: What are the uses of std::chrono::high_resolution_clock?. – Vocalize