Skip to content

Instantly share code, notes, and snippets.

@vovanmix
Last active March 1, 2017 08:02
Show Gist options
  • Save vovanmix/de168bb861ab1b5666e7722ba3a74388 to your computer and use it in GitHub Desktop.
Save vovanmix/de168bb861ab1b5666e7722ba3a74388 to your computer and use it in GitHub Desktop.
Simple curl benchmark
#!/bin/bash
URL="$1"
MAX_RUNS="$2"
SUM_TIME="0"
SUM_SIZE="0"
i="0"
while [ $i -lt $MAX_RUNS ]; do
TIME=`curl $URL -o /dev/null -s -w %{time_total}`
TIME="${TIME/,/.}"
SIZE=`curl $URL -o /dev/null -s -w %{size_download}`
SIZE="${SIZE/,/.}"
SUM_TIME=`echo "scale=5; $TIME + $SUM_TIME" | bc`
SUM_SIZE=`echo "scale=5; $SIZE + $SUM_SIZE" | bc`
i=$[$i+1]
done
TIME_AVERAGE=`echo "scale=5; $SUM_TIME / $MAX_RUNS * 1000" | bc`
SIZE_AVERAGE=`echo "scale=5; $SUM_SIZE / $MAX_RUNS / 1024" | bc`
echo "Time:"
echo "Sum: $SUM_TIME sec"
echo "Avg: $TIME_AVERAGE ms"
echo "Size:"
echo "Sum: $SUM_SIZE b"
echo "Avg: $SIZE_AVERAGE kb"
#./benchmark.sh http://localhost:80 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment