Run a timed code snippet repeatedly. Each elapsed time is an observation; the collected times form a statistical sample. A frequency histogram shows how often measured values occur. TAKEAWAY: assess performance from repeated measurements, not an isolated timing. section 15.3
Listing 15.2. Collecting time statistics with timespec_diff and stats_collect2
102 for (unsigned i = 0; i < loops; i++) {
103 double diff = timespec_diff(&t[i+1], &t[i]);
104 stats_collect2(&statistic[i], diff);
105 }
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":0,\"ch\":9},{\"line\":0,\"ch\":12}],[{\"line\":0,\"ch\":14},{\"line\":0,\"ch\":22}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":1,\"ch\":11},{\"line\":1,\"ch\":17}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":3}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":3}]]"}
!@%STYLE%@!
The loop computes each elapsed time with timespec_diff and adds it to a running statistic with stats_collect2. section 15.3
The mean summarizes the measured times, while relative standard deviation reports their variation. Neither removes measurement bias: calling timespec_get takes time and can change optimization opportunities, scheduling, or cache behavior. Keep that disturbance small enough to assess the result qualitatively. section 15.3






