Cargo has a basic, hierarchical profiler built-in. The environment variable
CARGO_PROFILE can be set to an integer which specifies how deep in the
profile stack to print results for.
# Output first three levels of profiling info CARGO_PROFILE=3 cargo generate-lockfile
Head over to the
directory for more
information about the benchmarking suite.
The overhead for starting a build should be kept as low as possible (preferably, well under 0.5 seconds on most projects and systems). Currently, the primary parts that affect this are:
- Running the resolver.
- Querying the index.
- Checking git dependencies.
- Scanning the local project.
- Building the unit dependency graph.
One way to test this is to use hyperfine. This is a tool that can be used to
measure the difference between different commands and settings. Usually this
is done by measuring the time it takes for
cargo build to finish in a large
project where the build is fresh (no actual compilation is performed). Just
cargo build once before using hyperfine.