Skip to content

Instantly share code, notes, and snippets.

@VorpalBlade
Created November 20, 2025 23:04
Show Gist options
  • Select an option

  • Save VorpalBlade/3ab71efbe8de8394217865cd4256c6f8 to your computer and use it in GitHub Desktop.

Select an option

Save VorpalBlade/3ab71efbe8de8394217865cd4256c6f8 to your computer and use it in GitHub Desktop.
Script to make system more predictable during benchmarking
#!/bin/bash
#
# Notes to self:
# * https://github.com/andrewrk/poop as an alternative to hyperfine
# * https://easyperf.net/blog/2019/08/02/Perf-measurement-environment-on-Linux
if [[ -z "$1" ]]; then
echo "Usage: $0 {bench|normal}"
exit 1
fi
case $1 in
bench)
type powerprofilesctl >/dev/null && powerprofilesctl set performance
if [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]]; then
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
fi
if [[ -f /sys/devices/system/cpu/cpufreq/boost ]]; then
echo 0 | sudo tee /sys/devices/system/cpu/cpufreq/boost
fi
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
echo performance | sudo tee $i
done
;;
normal)
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
echo powersave | sudo tee $i
done
if [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]]; then
echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
fi
if [[ -f /sys/devices/system/cpu/cpufreq/boost ]]; then
echo 1 | sudo tee /sys/devices/system/cpu/cpufreq/boost
fi
type powerprofilesctl >/dev/null && powerprofilesctl set balanced
;;
*)
echo "Invalid option. Use 'bench' or 'normal'."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment