Answer the question
In order to leave comments, you need to log in
How to properly measure code?
I wrote my bike to measure the speed of arithmetic operations https://github.com/DevAlone/CppCodeMeasurer
I measure time using std::chrono (highresolutiontimer.hpp file). I run the test function like this:
template <typename F, typename... Args>
Timer::precision CodeMeasurer::measure(F func, Args... args)
{
// делаем N повторений и записываем результат
for (size_t i = 0; i < NUM_OF_REPETITION; i++) {
t1.reset();
func(args...);
result = t1.elapsed();
results[i] = result;
}
// считаем среднее исключая крайние замеры
result = 0;
for (size_t i = NUM_OF_SKIPPED; i < NUM_OF_REPETITION - NUM_OF_SKIPPED; i++) {
result += results[i];
}
result /= NUM_OF_REPETITION - NUM_OF_SKIPPED * 2;
return result;
}
void exec()
{
for (size_t i = 0; i < NUM_OF_REPETITION; i++) {
val1 += val2;
val2 -= val2;
val1 *= val2;
}
}
g++ -O0 -o runIt ../main.cpp
sudo nice -n -20 ./runIt
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question