|
1 | 1 | # Benchmarks for Rust compiler performance
|
2 | 2 |
|
3 |
| -Each subdirectory contains a single benchmark. Although benchmarks may contain |
4 |
| -multiple crates, each benchmark has one "crate of interest" which is the one |
5 |
| -whose compilation time is measured. |
6 |
| - |
7 |
| -Each benchmark has a makefile with the following targets. |
8 |
| -* `all`: builds the entire benchmark. The following environment variables can |
9 |
| - be used to influence how it is built. |
10 |
| - * `CARGO_OPTS`: extra arguments to the `cargo` invocation. |
11 |
| - * `CARGO_RUSTC_OPTS`: extra arguments to `cargo rustc` invocations. |
12 |
| -* `touch`: touches or removes files in such a way that a subsequent `make` |
13 |
| - invocation will build only the crate of interest. |
14 |
| -* `clean`: removes all build artifacts. |
15 |
| - |
16 |
| -A historical record of timings is shown at: http://perf.rust-lang.org/. This |
17 |
| -site makes use of the `process.sh` script plus some auxiliary scripts not in |
18 |
| -this repository. |
| 3 | +Each subdirectory contains a single benchmark. Although benchmarks may |
| 4 | +contain multiple crates, each benchmark has one "crate of interest" |
| 5 | +which is the one whose compilation time is measured. However, to test |
| 6 | +incremental, the full benchmark may involve building that same crate |
| 7 | +many times in succession, applying a different patch each time. |
| 8 | + |
| 9 | +### How benchmarks work |
| 10 | + |
| 11 | +Each benchmark contains a makefile. This makefile defines various |
| 12 | +standard targets. The basic procedure for running a benchmark is defined |
| 13 | +in `process.sh` and looks like this: |
| 14 | + |
| 15 | +1. Invoke `make patches` to get a list of patches. This target should |
| 16 | + output a series of patches, or else output nothing. If it outputs nothing, |
| 17 | + that indicates that this is a non-incremental benchmark, and is treated |
| 18 | + as having a patches array with a single empty string `("")`. For incremental |
| 19 | + benchmarks, it would output a series of patch names like `@000-base` or |
| 20 | + `@010-foo`. By convention these begin with an `@` and a number that increments |
| 21 | + by 10 (000, 010, 020) --- this leaves room for inserting steps later. They |
| 22 | + then have a brief description. |
| 23 | +2. To run the benchmark, you then invoke `make all$PATCH` for each patch. |
| 24 | + So, for non-incremental tests, this is just `make all`. For incremental tests, |
| 25 | + it would be something like `make all@000-base`, followed by `make all@010-foo`, etc. |
| 26 | + - Each stage should run cargo to build the target crate. The basic |
| 27 | + invocation should be something like this, where `CARGO_OPTS` and |
| 28 | + `CARGO_RUSTC_OPTS` are variables set by `process.sh`: |
| 29 | + - `cargo rustc -p target_crate $CARGO_OPTS -- $CARGO_RUSTC_OPTS` |
| 30 | + - These `CARGO_RUSTC_OPTS` will include `-Z time-passes`, causing the compiler to |
| 31 | + emit timing information. This information is saved (by `process.sh`) into an intermediate |
| 32 | + file. It can later be scraped. |
| 33 | +3. After executing all the `make all@...` targets, `make touch` is used to reset the state |
| 34 | + to the initial state. We can then repeat step 2 as many times as desired. |
| 35 | +4. Finally, `make clean` is used to restore everything and remove any temporary data. |
| 36 | + |
| 37 | +### Local runs |
19 | 38 |
|
20 | 39 | Local runs comparing two different compilers can be performed with
|
21 | 40 | `compare.py`. Invocation is simple:
|
| 41 | + |
22 | 42 | > `./compare.py <rustc1> <rustc2>`
|
23 | 43 |
|
24 | 44 | This is useful when evaluating compile-time optimizations.
|
|
0 commit comments