Last active
October 28, 2021 19:18
-
-
Save nickdesaulniers/4a20ba10c26ac2ad02cb0425b8b0f826 to your computer and use it in GitHub Desktop.
average total cycle counts for 30 runs.
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
#!/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