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.

Bias is a systematic deviation between a measurement and the property it is intended to represent. In performance measurement, the act of timing code can change the execution being measured. section 16.4

Listing 16.2 Measuring calls to timespec_get repeatedly
    /* A function call can usually not be optimized out. */ 1 
    for (uint64_t i = 0; i < iterations; ++i) { 
      timespec_get(&tdummy, TIME_UTC);
      accu1 += tdummy.tv_nsec;
    }
    timespec_get(&t[4], TIME_UTC);
    

Repeated calls to timespec_get provide a way to assess the cost of the timing operation itself. section 16.4

A timing call takes time, but its effects can extend beyond that cost. The compiler may need to save registers and abandon optimization assumptions. A system call may also affect scheduling or invalidate data caches. Instrumentation can therefore change both compile-time and run-time properties. section 16.4

Assess timing bias before interpreting measurements of the code of interest. Repeat experiments and collect statistics such as the mean, standard deviation, and sometimes skew. Repetition helps characterize outcomes; it does not by itself remove a systematic effect of instrumentation. section 16.4

How Modern C, Third Edition covers it

How deep it goes
Explains timing overhead and compiler and runtime effects, then outlines repeated measurement and statistics; defers a full treatment of measurement.
Examples
Uses repeated timespec_get calls and timed loops to illustrate measurement overhead.
What you can do after
Evaluate timing results by considering instrumentation effects and summarizing repeated measurements.
How it connects
Connects bias to instrumentation, compiler optimization, scheduling, data caches, and descriptive statistics.

Also explained in

Compare how 29 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.