Skip to content

Instantly share code, notes, and snippets.

@nickdesaulniers
Last active October 28, 2021 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdesaulniers/4a20ba10c26ac2ad02cb0425b8b0f826 to your computer and use it in GitHub Desktop.
Save nickdesaulniers/4a20ba10c26ac2ad02cb0425b8b0f826 to your computer and use it in GitHub Desktop.
average total cycle counts for 30 runs.
#!/usr/bin/env sh
# Usage: ./measure_30.sh 'code to measure' 'setup code not to measure'
tempfile=$(mktemp)
count=30
for i in $(seq 1 $count); do
eval $2
perf stat -B -e cycles:u $1 2>&1 1>/dev/null | grep cycles:u | awk '{ $1=$1 };1' | cut -d ' ' -f 1 | tr -d , | tee --append $tempfile
done
total=0
for i in $(awk '{ print $1; }' $tempfile); do
total=$(echo $total+$i | bc)
done
echo "scale=2; $total / $count" | bc | xargs printf "Average of 30 runs: %s cycles\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment