From a63882bece79cc7a370ec4d772b23d2849c181df Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Wed, 4 Sep 2024 16:21:18 -0300 Subject: [PATCH] benchmark,doc: add CPU scaling governor to perf PR-URL: https://github.com/nodejs/node/pull/54723 Reviewed-By: Yagiz Nizipli Reviewed-By: Matteo Collina --- benchmark/cpu.sh | 24 +++++++++++++++++++ .../writing-and-running-benchmarks.md | 10 ++++++++ 2 files changed, 34 insertions(+) create mode 100755 benchmark/cpu.sh diff --git a/benchmark/cpu.sh b/benchmark/cpu.sh new file mode 100755 index 00000000000..9c9dd7fa4dd --- /dev/null +++ b/benchmark/cpu.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +CPUPATH=/sys/devices/system/cpu + +MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}') + +set_governor() { + echo "Setting CPU frequency governor to \"$1\"" + i=0 + while [ "$i" -le "$MAXID" ]; do + echo "$1" > "$CPUPATH/cpu$i/cpufreq/scaling_governor" + i=$((i + 1)) + done +} + +case "$1" in + fast | performance) + set_governor "performance" + ;; + *) + echo "Usage: $0 fast" + exit 1 + ;; +esac diff --git a/doc/contributing/writing-and-running-benchmarks.md b/doc/contributing/writing-and-running-benchmarks.md index 21059252926..c258280ce95 100644 --- a/doc/contributing/writing-and-running-benchmarks.md +++ b/doc/contributing/writing-and-running-benchmarks.md @@ -94,6 +94,16 @@ A list of mirrors is [located here](https://cran.r-project.org/mirrors.html). ## Running benchmarks +### Setting CPU Frequency scaling governor to "performance" + +It is recommended to set the CPU frequency to `performance` before running +benchmarks. This increases the likelihood of each benchmark achieving peak performance +according to the hardware. Therefore, run: + +```console +$ ./benchmarks/cpu.sh fast +``` + ### Running individual benchmarks This can be useful for debugging a benchmark or doing a quick performance