liveBook · Manning

Statistical sample

As explained in Modern C, Third Edition

A statistical sample is a finite collection of observed values drawn from a phenomenon or experiment.

A statistical sample is a finite set of observed values. For a performance measurement, collect timings from repeated runs rather than treating one timing as definitive. Each observation can vary, and the measurement itself can change the program being measured. section 16.4

Collecting and reporting timings

For each timed interval, `timespec_diff(&t[i+1], &t[i])` produces a duration, and `stats_collect2(&statistic[i], diff)` adds it to the sample. `stats_mean` and `stats_rsdev_unbiased` then report its mean and relative variation. These summaries help distinguish a convincing performance difference from one obscured by variation; they do not prove an algorithm’s complexity. section 16.4

Figure 16.1 Frequency histogram for our sample, showing the frequency with which each of the measured values was obtained
figure

The frequency histogram shows how often each measured value occurred, making the sample’s distribution visible. section 16.4

TAKEAWAY: Account for instrumentation when interpreting a timing sample. A `timespec_get` call takes time and can affect optimization, scheduling, and caches. section 16.4

How Modern C, Third Edition covers it

How deep it goes
Shows collection, summary statistics, and a histogram, while leaving complexity proofs and a full treatment of measurement outside scope.
Examples
Uses repeated C timings, statistics-collection calls, printed timing summaries, and a frequency histogram.
What it assumes
Assumes familiarity with C loops and function calls; introduces sampling through concrete timing measurements.
What you can do after
Diagnose/debug with it by comparing timing summaries while checking whether variation and instrumentation undermine a performance claim.
How it connects
Connects samples to performance measurement, instrumentation bias, histograms, mean, and relative standard deviation.

Also explained in

Compare how 7 books explain statistical sample →

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.