Twenty timing measurements
Twenty repeated timings range from 0.1 to 1.3 seconds. Their sum is 12 seconds, so their mean, μ(S), is 12 ÷ 20 = 0.6 seconds. That single value does not show how widely the timings vary. section 16.4
A mean is the arithmetic average: add the measured values and divide by their number. In performance measurement, repeat an experiment and consider the mean alongside its standard deviation. Here the standard deviation is 0.31 seconds; reporting 0.6 seconds alone would conceal substantial variation. Measurement itself can also introduce bias. section 16.4
Listing 16.5 Printing time stats with stats_mean and stats_rsdev_unbiased
for (unsigned i = 0; i < loops; i++) {
double mean = stats_mean(&statistic[i]);
double rsdev = stats_rsdev_unbiased(&statistic[i]);
printf("loop %u: E(t) (sec):\t%5.2e ± %4.02f%%,\tloop body %5.2e\n",
i, mean, 100.0*rsdev, mean/iterations);
}
The C listing obtains a mean with stats_mean, reports relative deviation beside it, and divides the mean by the iteration count to report time per loop body. section 16.4




























