1 # Benchmarking and Profiling
5 Cargo 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
7 profile stack to print results for.
10 # Output first three levels of profiling info
11 CARGO_PROFILE=3 cargo generate-lockfile
18 Head over to the [`benches`
19 directory](https://github.com/rust-lang/cargo/tree/master/benches) for more
20 information about the benchmarking suite.
22 ### Informal benchmarking
24 The 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,
26 the primary parts that affect this are:
28 * Running the resolver.
30 * Checking git dependencies.
31 * Scanning the local project.
32 * Building the unit dependency graph.
34 One way to test this is to use [hyperfine]. This is a tool that can be used to
35 measure the difference between different commands and settings. Usually this
36 is done by measuring the time it takes for `cargo build` to finish in a large
37 project where the build is fresh (no actual compilation is performed). Just
38 run `cargo build` once before using hyperfine.
40 [hyperfine]: https://github.com/sharkdp/hyperfine