c++: calculate average time taken based on samples