Iai-Callgrind

Iai-Callgrind is divided into the library iai-callgrind and the benchmark runner iai-callgrind-runner.

Installation of the library

To start with Iai-Callgrind, add the following to your Cargo.toml file:

[dev-dependencies]
iai-callgrind = "0.14.0"

or run

cargo add --dev iai-callgrind@0.14.0

Installation of the benchmark runner

To be able to run the benchmarks you'll also need the iai-callgrind-runner binary installed somewhere in your $PATH. Otherwise, there is no need to interact with iai-callgrind-runner as it is just an implementation detail.

From Source

cargo install --version 0.14.0 iai-callgrind-runner

There's also the possibility to install the binary somewhere else and point the IAI_CALLGRIND_RUNNER environment variable to the absolute path of the iai-callgrind-runner binary like so:

cargo install --version 0.14.0 --root /tmp iai-callgrind-runner
IAI_CALLGRIND_RUNNER=/tmp/bin/iai-callgrind-runner cargo bench --bench my-bench

Binstall

The iai-callgrind-runner binary is pre-built for most platforms supported by valgrind and easily installable with binstall

cargo binstall iai-callgrind-runner@0.14.0

Updating

When updating the iai-callgrind library, you'll also need to update iai-callgrind-runner and vice-versa or else the benchmark runner will exit with an error.

In the Github CI

Since the iai-callgrind-runner version must match the iai-callgrind library version it's best to automate this step in the CI. A job step in the github actions CI could look like this

- name: Install iai-callgrind-runner
  run: |
    version=$(cargo metadata --format-version=1 |\
      jq '.packages[] | select(.name == "iai-callgrind").version' |\
      tr -d '"'
    )
    cargo install iai-callgrind-runner --version $version

Or, speed up the overall installation time with binstall using the taiki-e/install-action

- uses: taiki-e/install-action@cargo-binstall
- name: Install iai-callgrind-runner
  run: |
    version=$(cargo metadata --format-version=1 |\
      jq '.packages[] | select(.name == "iai-callgrind").version' |\
      tr -d '"'
    )
    cargo binstall --no-confirm iai-callgrind-runner --version $version