|
| 1 | +# Benchmarking Clippy |
| 2 | + |
| 3 | +Benchmarking Clippy is similar to using our Lintcheck tool, in fact, it even |
| 4 | +uses the same tool! Just by adding a `--perf` flag it will transform Lintcheck |
| 5 | +into a very simple but powerful benchmarking tool! |
| 6 | + |
| 7 | +It requires having the [`perf` tool][perf] installed, as `perf` is what's actually |
| 8 | +profiling Clippy under the hood. |
| 9 | + |
| 10 | +The lintcheck `--perf` tool generates a series of `perf.data` in the |
| 11 | +`target/lintcheck/sources/<package>-<version>` directories. Each `perf.data` |
| 12 | +corresponds to the package which is contained. |
| 13 | + |
| 14 | +Lintcheck uses the `-g` flag, meaning that you can get stack traces for richer |
| 15 | +analysis, including with tools such as [flamegraph][flamegraph-perf] |
| 16 | +(or [`flamegraph-rs`][flamegraph-rs]). |
| 17 | + |
| 18 | +Currently, we only measure instruction count, as it's the most reproducible metric |
| 19 | +and rustc-perf also considers it the main number to focus on. |
| 20 | + |
| 21 | +## Benchmarking a PR |
| 22 | + |
| 23 | +Having a benchmarking tool directly implemented into lintcheck gives us the |
| 24 | +ability to benchmark any given PR just by making a before and after |
| 25 | + |
| 26 | +Here's the way you can get into any PR, benchmark it, and then benchmark |
| 27 | +`master`. |
| 28 | + |
| 29 | +The first `perf.data` will not have any numbers appended, but any subsequent |
| 30 | +benchmark will be written to `perf.data.number` with a number growing for 0. |
| 31 | +All benchmarks are compressed so that you can |
| 32 | + |
| 33 | +```bash |
| 34 | +git fetch upstream pull/<PR_NUMBER>/head:<BRANCH_NAME> |
| 35 | +git switch BRANCHNAME |
| 36 | + |
| 37 | +# Bench |
| 38 | +cargo lintcheck --perf |
| 39 | + |
| 40 | +# Get last common commit, checkout that |
| 41 | +LAST_COMMIT=$(git log BRANCHNAME..master --oneline | tail -1 | cut -c 1-11) |
| 42 | +git switch -c temporary $LAST_COMMIT |
| 43 | + |
| 44 | +# We're now on master |
| 45 | + |
| 46 | +# Bench |
| 47 | +cargo lintcheck --perf |
| 48 | +perf diff ./target/lintcheck/sources/CRATE/perf.data ./target/lintcheck/sources/CRATE/perf.data.0 |
| 49 | +``` |
| 50 | + |
| 51 | + |
| 52 | +[perf]: https://perfwiki.github.io/main/ |
| 53 | +[flamegraph-perf]: https://github.com/brendangregg/FlameGraph |
| 54 | +[flamegraph-rs]: https://github.com/flamegraph-rs/flamegraph |
| 55 | +[rustc-perf]: |
0 commit comments