Sub topic 6
Reading the console output and HTML report
This chapter assumes you can already run cargo bench on a Criterion benchmark with harness = false, as set up in the earlier chapters. It also assumes you know what a confidence interval is in rough terms: a range that probably contains the true value. Here you learn to read each line Criterion prints and each chart it draws, so you can tell a real change from noise.
The shape of a Criterion run
Criterion prints progress while it works, then a short result block for each benchmark. The progress lines show the phases of the measurement model:
Benchmarking fib 20
Benchmarking fib 20: Warming up for 3.0000 s
Benchmarking fib 20: Collecting 100 samples in estimated 5.0003 s (192k iterations)
Benchmarking fib 20: Analyzing
fib 20 time: [26.029 µs 26.251 µs 26.505 µs]
change: [-0.8412% +0.1263% +1.0471%] (p = 0.80 > 0.05)
No change in performance detected.
Found 7 outliers among 100 measurements (7.00%)
4 (4.00%) high mild
3 (3.00%) high severeThe numbers vary from machine to machine. The structure does not. Each block has up to four parts:
- The
time:line, which is the estimate. - The
change:line and its verdict, which compare against the previous run. - The outlier summary, which describes the quality of the samples.
- Optional lines such as
thrpt:when you declared a throughput.
The warm-up line shows how long Criterion ran the code before measuring. The "Collecting" line shows how many samples it will take (100 by default), the time it estimates that needs, and the total iterations spread across those samples.
The time line
time: [26.029 µs 26.251 µs 26.505 µs]The three numbers are a lower bound, a point estimate, and an upper bound. Together they form a 95% confidence interval for the time of one iteration. The middle value is the best single estimate. For most benchmarks it is the slope of a linear regression of total sample time against iteration count, not a simple average. The slope approach removes fixed per-sample overhead, such as reading the clock.
A narrow interval means the measurement was stable. A wide interval, for example [20 µs 26 µs 35 µs], means the machine was noisy or the code has inherently variable timing. Do not trust small differences in that case.
Units scale automatically between ps, ns, µs, ms, and s. Check the unit before comparing two results. A drop from 1.2 ms to 900 µs is a real improvement even though 900 is a smaller-looking number than 1.2 only by coincidence of units.
The change line
From the second run onward, Criterion compares the new samples with the ones saved in target/criterion from the previous run. The change: line has the same three-value form, but the values are relative changes in time.
change: [-8.1209% -7.4120% -6.6881%] (p = 0.00 < 0.05)
Performance has improved.A negative change means the code got faster. A positive change means it got slower. The p value comes from a statistical test of whether the two sets of samples differ. Criterion prints one of four verdicts:
| Verdict | Meaning |
|---|---|
| `No change in performance detected.` | The p-value is above 0.05, so the difference could be noise. |
| `Change within noise threshold.` | The difference is statistically significant but smaller than the noise threshold (1% by default). |
| `Performance has improved.` | Significant, and the time went down by more than the noise threshold. |
| `Performance has regressed.` | Significant, and the time went up by more than the noise threshold. |
Two settings control this decision: the significance level (0.05) and the noise threshold (0.01). The noise threshold exists because with enough samples even a 0.3% difference becomes statistically significant, and it is rarely worth acting on. Both can be changed through Criterion::significance_level and Criterion::noise_threshold.
You can also see the verdict "Performance has regressed" on a run where you changed nothing. Code that has not changed can still shift if another process used the CPU, if the CPU throttled, or if a laptop was on battery. Treat a single flagged regression as a prompt to re-run, not as proof.
Outliers
Found 7 outliers among 100 measurements (7.00%)
4 (4.00%) high mild
3 (3.00%) high severeCriterion classifies each sample using Tukey's fences, which are based on the interquartile range (IQR), the spread of the middle half of the samples. A sample is a mild outlier if it lies more than 1.5 IQR beyond the quartiles, and a severe outlier if it lies more than 3 IQR beyond. The four labels are low mild, low severe, high mild, and high severe.
Criterion reports outliers but does not discard them. They still enter the estimate. High outliers are the common case, and they usually come from interruptions such as a context switch or a background task. A few percent is normal. If more than about 10% of samples are outliers, or the severe count is high, the environment is probably noisy. Close other programs, plug in the machine, and run again.
Low outliers are rarer and can point to cache effects or to branch predictors that learned the input.
Warnings about measurement time
For slow benchmarks Criterion may print a warning like this:
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 20.2s, enable flat sampling, or reduce sample count to 60.Criterion tries to collect all samples within the measurement time, 5 seconds by default. If one iteration is slow, 100 samples cannot fit. The numbers are still valid, but Criterion exceeded its time budget to collect them. The three fixes it suggests are covered in the chapter on configuration: a longer measurement_time, a smaller sample_size, or SamplingMode::Flat.
The HTML report
With the html_reports feature enabled in Cargo.toml, every run writes charts into target/criterion. Open the main page in a browser:
cargo bench
# Linux: xdg-open, macOS: open, Windows: start
xdg-open target/criterion/report/index.htmlThis page lists every benchmark. Each benchmark also has its own page at target/criterion/<group>/<name>/report/index.html. For a function named fib 20 the directory is target/criterion/fib 20/report/.
Replace nothing above; the actual diagram follows.
The charts on a benchmark page
- Probability density function (PDF). A smoothed histogram of the time per iteration. A single tight peak is healthy. A second bump suggests two distinct behaviors, such as a cache hit versus a miss, or a noisy neighbor. The chart marks the mean, and the shaded region shows the range of the samples.
- Regression. Each dot is one sample, plotted as total iterations against total time. The line is the fitted slope. Dots close to the line mean consistent timing. The slope of the line is the number on the
time:line. - Iteration times. Replaces the regression chart when the benchmark uses flat sampling. Each dot is the time per iteration for one sample, in order. Look for a trend, such as times drifting upward, which can mean thermal throttling or memory growth.
- Change charts. After a second run, extra charts compare the new and old distributions and show the bootstrapped distribution of the relative change.
The statistics table on the page lists the lower bound, estimate, and upper bound for each of these:
| Statistic | What it tells you |
|---|---|
| Slope | The regression estimate used on the console `time:` line. |
| R² | How well a straight line fits the samples. Values close to 1.0 are good. |
| Mean | The plain average of time per iteration. |
| Std. Dev. | The spread of the samples. |
| Median | The middle sample, which resists outliers. |
| MAD | Median absolute deviation, a spread measure that resists outliers. |
Check R² first. Values well below 0.99 suggest that something other than your code affected the timing. Then compare the slope and the median. If they differ by a lot, outliers or a skewed distribution are pulling on the result.
Plots without the HTML feature
Without html_reports, Criterion tries to use gnuplot for plots, and prints Gnuplot not found, using plotters backend if it is missing. The console output is the same either way. The HTML pages require the feature flag shown in the setup chapter.
Putting it together
Use this routine whenever you read a result:
- Check the interval width on the
time:line. If it spans more than a few percent, treat the result as noisy. - Check the outlier count. Many severe outliers mean you should fix the environment before drawing conclusions.
- Read the
change:verdict, but also look at the size of the change. A "regressed" verdict of +0.5% is below most practical thresholds. - Open the report page. Confirm that the PDF has one peak and R² is near 1.
- If a result surprises you, run the benchmark again before changing code.
Exercise
A benchmark prints time: [10.2 ms 10.4 ms 10.6 ms], then change: [+0.4% +0.9% +1.4%] (p = 0.03 < 0.05) and the verdict "Change within noise threshold." Did the code get slower, and should you treat it as a regression? Also, what does it mean if the same run reports "Found 18 outliers among 100 measurements (18.00%)", with 12 of them high severe?
Show answer
The p-value is below 0.05, so the difference is statistically significant, and the positive change means the code was about 0.9% slower. Because 0.9% is under the default 1% noise threshold, Criterion does not call it a regression, and it is rarely worth acting on. The 18% outlier rate, with many severe high outliers, means the samples were disturbed, probably by other processes or CPU frequency changes. The result should be treated as unreliable until you re-run in a quieter environment.