Skip to content

Commit d7a9989

Browse files
committed
add command to run our benchmarks
1 parent 04a0135 commit d7a9989

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ does not automatically trigger a re-build of the standard library; you have to
147147
clear the Miri build cache manually (on Linux, `rm -rf ~/.cache/miri`;
148148
and on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`).
149149

150+
### Benchmarking
151+
152+
Miri comes with a few benchmarks; you can run `./miri bench` to run them with the locally built
153+
Miri. Note: this will run `./miri install` as a side-effect. Also requires `hyperfine` to be
154+
installed (`cargo install hyperfine`).
155+
150156
## Configuring `rust-analyzer`
151157

152158
To configure `rust-analyzer` and VS Code for working on Miri, save the following

miri

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Runs <command> over and over again with different seeds for Miri. The MIRIFLAGS
3737
variable is set to its original value appended with ` -Zmiri-seed=$SEED` for
3838
many different seeds.
3939
40+
./miri bench <benches>:
41+
Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed.
42+
<benches> can explicitly list the benchmarks to run; by default, all of them are run.
43+
4044
ENVIRONMENT VARIABLES
4145
4246
MIRI_SYSROOT:
@@ -47,6 +51,11 @@ Pass extra flags to all cargo invocations.
4751
EOF
4852
)
4953

54+
## Preparation
55+
# macOS does not have a useful readlink/realpath so we have to use Python instead...
56+
MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0")
57+
TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
58+
5059
# Determine command.
5160
COMMAND="$1"
5261
[ $# -gt 0 ] && shift
@@ -60,14 +69,23 @@ many-seeds)
6069
done
6170
exit 0
6271
;;
72+
bench)
73+
# Make sure we have an up-to-date Miri installed
74+
"$0" install
75+
# Run the requested benchmarks
76+
if [ -z "$@" ]; then
77+
BENCHES=( $(ls "$MIRIDIR/bench-cargo-miri" ) )
78+
else
79+
BENCHES=("$@")
80+
fi
81+
for BENCH in "${BENCHES[@]}"; do
82+
hyperfine -w 1 -m 5 --shell=none "cargo +$TOOLCHAIN miri run --manifest-path bench-cargo-miri/$BENCH/Cargo.toml"
83+
done
84+
exit 0
85+
;;
6386
esac
6487

65-
## Preparation
66-
# macOS does not have a useful readlink/realpath so we have to use Python instead...
67-
MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0")
68-
# Determine toolchain *in the Miri dir* and use that.
69-
TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
70-
88+
## Prepare the environment
7189
# Determine some toolchain properties
7290
TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2)
7391
SYSROOT=$(rustc +$TOOLCHAIN --print sysroot)

0 commit comments

Comments
 (0)