]> git.proxmox.com Git - rustc.git/blame - src/tools/cargo/src/doc/contrib/src/tests/profiling.md
New upstream version 1.70.0+dfsg2
[rustc.git] / src / tools / cargo / src / doc / contrib / src / tests / profiling.md
CommitLineData
0a29b90c
FG
1# Benchmarking and Profiling
2
3## Internal profiler
4
5Cargo has a basic, hierarchical profiler built-in. The environment variable
6`CARGO_PROFILE` can be set to an integer which specifies how deep in the
7profile stack to print results for.
8
9```sh
10# Output first three levels of profiling info
11CARGO_PROFILE=3 cargo generate-lockfile
12```
13
14## Benchmarking
15
16### Benchsuite
17
18Head over to the [`benches`
19directory](https://github.com/rust-lang/cargo/tree/master/benches) for more
20information about the benchmarking suite.
21
22### Informal benchmarking
23
24The overhead for starting a build should be kept as low as possible
25(preferably, well under 0.5 seconds on most projects and systems). Currently,
26the primary parts that affect this are:
27
28* Running the resolver.
29* Querying the index.
30* Checking git dependencies.
31* Scanning the local project.
32* Building the unit dependency graph.
33
34One way to test this is to use [hyperfine]. This is a tool that can be used to
35measure the difference between different commands and settings. Usually this
36is done by measuring the time it takes for `cargo build` to finish in a large
37project where the build is fresh (no actual compilation is performed). Just
38run `cargo build` once before using hyperfine.
39
40[hyperfine]: https://github.com/sharkdp/hyperfine