-
-
Save rhysd/1324f6726f8905f4e71c0f549cb35d97 to your computer and use it in GitHub Desktop.
Try Rust PGO with wain project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
set -x | |
cargo --version | |
rustc --version | |
executable=wain | |
llvm_profdata="${LLVM_PROFDATA_BIN:="llvm-profdata"}" | |
pgodir="${PROF_DIR:="$(pwd)/pgo-data"}" | |
rm -rf "$pgodir" | |
mkdir -p "$pgodir" | |
cargo clean | |
# `cargo rustc` only passes options to target crate but we want to pass options to all dependant crates | |
# $ cargo rustc --verbose --release -- -Cprofile-generate="$pgodir" | |
CARGO_BUILD_RUSTFLAGS="-Cprofile-generate=${pgodir}" cargo build --verbose --release | |
wasm_files=(examples/*.{wasm,wat}) | |
id=$((0)) | |
for file in "${wasm_files[@]}"; do | |
if [[ "$file" =~ guessing_game ]]; then | |
# Skip because it requires interaction | |
continue | |
fi | |
"./target/release/${executable}" "$file" | |
((id++)) | |
done | |
$llvm_profdata merge -o "${pgodir}/merged.profdata" "$pgodir" | |
rm -f "${executable}-pgo" "${executable}-orig" | |
cargo clean | |
# `cargo rustc` only passes options to target crate but we want to pass options to all dependant crates | |
CARGO_BUILD_RUSTFLAGS="-Cprofile-use=${pgodir}/merged.profdata" cargo build --verbose --release | |
cp "./target/release/${executable}" "${executable}-pgo" | |
# For comparison | |
cargo clean | |
cargo build --verbose --release | |
cp "./target/release/${executable}" "${executable}-orig" | |
rm -f pgo_results.md | |
touch pgo_results.md | |
for file in "${wasm_files[@]}"; do | |
if [[ "$file" =~ guessing_game ]]; then | |
# Skip because it requires interaction | |
continue | |
fi | |
hyperfine --export-markdown tmp.md "./${executable}-orig $file" "./${executable}-pgo $file" | |
printf '\n### %s\n\n' "${file}" >> pgo_results.md | |
cat tmp.md >> pgo_results.md | |
rm -f tmp.md | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment