I have a program that basically calculate the rolling-average and other rolling-statistics of a very large vector in C++. For a vector with size N, I would like to get another vector of size N with element k containing rolling statistics from 0 to k. I will just use rolling average for illustration below.
The program has an object with a function that update the rolling statistics based on the new value and previous statistics value. For example:
inline float update(const float x) {
_n++;
_mean += (x - _mean)/_n;
return _mean;
}
Now I would like to support other statistics calculation, such as rolling standard deviation, and the plan is to add a pure virtual class as the base class with a pure virtual step function, and create different child classes corresponding to different statistics types.
My question here is: because the step function will be the main part for the function and will be executed billions of times, shall I expect the slow down by switch from an inline function to a virtual function significant? Is there other more efficient alternative for what I want to do? Or maybe I am not using the correct design pattern and there are other better ways to do it?