Skip to content

Benchmarking Vc

Matthias Kretz edited this page Oct 17, 2016 · 2 revisions

Benchmarking is harder than it should be. The main reason is the complexity of current CPUs that are able to squeeze out the last 0.1% of performance at highest power-efficiency. So, to get more understandable and reliable numbers we need to dial back a bit on the CPU and increase power usage a bit. Here's the script I use:

#!/bin/sh

no_turbo=/sys/devices/system/cpu/intel_pstate/no_turbo

turn_on() {
  echo performance | tee /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor >/dev/null
  if test -f $no_turbo; then
    echo 1 > $no_turbo
  else
    freq=$(cut -d" " -f1,2 /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies)
    freq1=${freq% *}
    freq2=${freq#* }
    test $(($freq2+1000)) -eq $freq1 && \
      echo $freq2 | tee /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_max_freq >/dev/null
  fi
}

turn_off() {
  if test -f $no_turbo; then
    echo powersave | tee /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor >/dev/null
    echo 0 > $no_turbo
  else
    freq=$(cut -d" " -f1 /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies)
    echo $freq | tee /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_max_freq >/dev/null
    echo ondemand | tee /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor >/dev/null
  fi
}

if test `id -u` = 0; then
  case "$1" in
    -h|--help)
      echo "Usage: $0 {on|off|-i}"
      ;;
    on|start)  turn_on ;;
    off|stop) turn_off ;;
    -i|--interactive|*)
      while true; do
        echo -n "Press Enter to turn benchmark modus on: "
        read tmp
        turn_on
        echo -n "Press Enter to turn benchmark modus off:"
        read tmp
        turn_off
      done
      ;;
  esac
else
  sudo $0 "$@"
fi
Clone this wiki locally