diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a3bad3d1540..bde1921eb8c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -147,6 +147,12 @@ does not automatically trigger a re-build of the standard library; you have to clear the Miri build cache manually (on Linux, `rm -rf ~/.cache/miri`; and on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`). +### Benchmarking + +Miri comes with a few benchmarks; you can run `./miri bench` to run them with the locally built +Miri. Note: this will run `./miri install` as a side-effect. Also requires `hyperfine` to be +installed (`cargo install hyperfine`). + ## Configuring `rust-analyzer` To configure `rust-analyzer` and VS Code for working on Miri, save the following diff --git a/miri b/miri index da5634d6a95..2debf70c166 100755 --- a/miri +++ b/miri @@ -37,6 +37,10 @@ Runs over and over again with different seeds for Miri. The MIRIFLAGS variable is set to its original value appended with ` -Zmiri-seed=$SEED` for many different seeds. +./miri bench : +Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed. + can explicitly list the benchmarks to run; by default, all of them are run. + ENVIRONMENT VARIABLES MIRI_SYSROOT: @@ -47,6 +51,11 @@ Pass extra flags to all cargo invocations. EOF ) +## Preparation +# macOS does not have a useful readlink/realpath so we have to use Python instead... +MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0") +TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1) + # Determine command. COMMAND="$1" [ $# -gt 0 ] && shift @@ -60,14 +69,23 @@ many-seeds) done exit 0 ;; +bench) + # Make sure we have an up-to-date Miri installed + "$0" install + # Run the requested benchmarks + if [ -z "$@" ]; then + BENCHES=( $(ls "$MIRIDIR/bench-cargo-miri" ) ) + else + BENCHES=("$@") + fi + for BENCH in "${BENCHES[@]}"; do + hyperfine -w 1 -m 5 --shell=none "cargo +$TOOLCHAIN miri run --manifest-path bench-cargo-miri/$BENCH/Cargo.toml" + done + exit 0 + ;; esac -## Preparation -# macOS does not have a useful readlink/realpath so we have to use Python instead... -MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0") -# Determine toolchain *in the Miri dir* and use that. -TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1) - +## Prepare the environment # Determine some toolchain properties TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2) SYSROOT=$(rustc +$TOOLCHAIN --print sysroot)