liveBook · Manning

Standard deviation

As explained in Modern C, Third Edition

Standard deviation measures the typical dispersion of observed values around their mean.

Suppose a code fragment is timed 20 times. The mean is 0.6 seconds, but individual timings range from 0.1 to 1.3 seconds. A mean alone hides that variation. section 16.4

The sample’s standard deviation, σ(S), is 0.31 seconds. It measures departure from the ideal of identical timings. Because 0.31 is substantial beside the 0.6-second mean, these measurements give little grounds for a confident performance claim. Variation could come from the computation, the measurement, or both. 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 prints each loop’s mean timing alongside an unbiased relative standard deviation, expressed as a percentage. section 16.4

TAKEAWAY: Repeat timings and inspect their spread before treating an average as representative. Measurement itself can change compile-time and run-time behavior. section 16.4

How Modern C, Third Edition covers it

How deep it goes
Defines its interpretation and works through one timing sample, without deriving a formula.
Examples
Uses 20 timings with a 0.6-second mean and 0.31-second standard deviation, plus C timing-statistics output.
What you can do after
Evaluate/understand whether variation makes an average timing unreliable.
How it connects
Relates standard deviation to the mean, repeated measurements, measurement bias, and relative deviation.

Also explained in

Compare how 15 books explain standard deviation →

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.