liveBook · Manning

Mean

As explained in Modern C, Third Edition

A mean value is the arithmetic average of a collection of numeric values.

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

How Modern C, Third Edition covers it

How deep it goes
Works through a twenty-timing sample and shows C reporting code, but does not develop a mean-calculation implementation.
Examples
Uses twenty timings with a 0.6-second mean and a C listing that prints mean time per loop body.
What it assumes
Assumes familiarity with C timing code; introduces the mean through numeric measurements.
What you can do after
Evaluate/understand repeated timing results without mistaking their mean for evidence of consistency.
How it connects
Relates the mean to standard deviation, relative deviation, measurement bias, and performance instrumentation.

Also explained in

Compare how 29 books explain mean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.