liveBook · Manning

Bias

As explained in Modern C, Third Edition

Bias is a systematic deviation between an observed measurement and the property it is intended to represent.

A timing call changes the run

A C loop timed with `timespec_get(&t[0], TIME_UTC)` before it and `timespec_get(&t[1], TIME_UTC)` after it includes the cost of measuring. The calls may also change how the compiler optimizes the surrounding code. section 16.4

Bias is the deviation measurement introduces into the result it is meant to report. A timing call takes time, may require registers to be saved, and can affect scheduling or caches. TAKEAWAY: instrumentation changes both compile-time and run-time behavior. Assess that effect before treating a measured duration as the cost of the code alone. section 16.4

Table 16.1 Comparison of measurements
Loop Sec per iteration Difference Gain/loss Conclusive
0 volatile loop 1.97⋅10-09
1 volatile store 3.66⋅10-10 -1.60⋅10-09 -81% Yes
2 Opaque addition 3.45⋅10-10 -2.10⋅10-11 -6% No
3 Plus timespec_get 1.77⋅10-08 1.74⋅10-08 +5043% Yes
4 Plus mean 2.62⋅10-08 8.5⋅10-09 +48% Yes
5 Plus variance 2.90⋅10-08 2.8⋅10-09 +11% Yes
6 Plus skew 3.17⋅10-08 2.7⋅10-09 +9% Yes

The comparison separates loop costs from the much larger per-iteration costs of adding `timespec_get` and statistical collection. section 16.4

Repeat experiments and collect statistics, including the mean and standard deviation, to help assess results. Repetition does not make the measurement apparatus disappear. section 16.4

How Modern C, Third Edition covers it

How deep it goes
Explains timing interference through compiler optimization, system calls, scheduling, and caches; defers a full treatment of experimental measurement.
Examples
Compares timed C loops with calls to timespec_get and added statistical collection.
What it assumes
Assumes familiarity with C loops and function calls while introducing measurement bias through a concrete timing example.
What you can do after
Evaluate/understand it by assessing measurement overhead before interpreting performance comparisons.
How it connects
Connects bias to instrumentation, compiler optimization, system calls, mean, and standard deviation.

Also explained in

Compare how 28 books explain bias →

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.