Last active
February 4, 2022 14:55
-
-
Save stig/c7a13879534126fbf56c to your computer and use it in GitHub Desktop.
Print percentiles for list of data points
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
#!/bin/sh | |
# Exit immediately on error | |
set -e | |
# set -x | |
# Create temporary file | |
FILE=$(mktemp /tmp/$(basename $0).XXXXX) || exit 1 | |
trap "rm -f $FILE" EXIT | |
# Sort entries | |
sort -n $* > $FILE | |
# Count number of data points | |
N=$(wc -l $FILE | awk '{print $1}') | |
# Calculate line numbers for each percentile we're interested in | |
P50=$(dc -e "$N 2 / p") | |
P90=$(dc -e "$N 9 * 10 / p") | |
P99=$(dc -e "$N 99 * 100 / p") | |
echo ";; 50th, 90th and 99th percentiles for $N data points" | |
awk "FNR==$P50 || FNR==$P90 || FNR==$P99" $FILE |
99th but not 1st/25th?
Most requests were pretty quick, so 1st and 25th were not really useful at the time, but we had a few that were very anomalous. Hence the 90 and 99. You can of course change them to / or add whatever you need.
PS: Thanks for the suggestion of removing the temporary file. I've added a trap
statement to take care of that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
99th but not 1st/25th? :) also may want to delete that temp file after you'r done with it :|