Skip to content

Instantly share code, notes, and snippets.

@tomfa
Last active December 1, 2018 11:01
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 tomfa/2509a9a6695462df928d7fe30c25d787 to your computer and use it in GitHub Desktop.
Save tomfa/2509a9a6695462df928d7fe30c25d787 to your computer and use it in GitHub Desktop.
# Simple curl benchmarking
#
# Example: 10 (sequential) calls towards google.com
# sh benchmark.sh 10 http://google.com
#
# Output:
# Running 10 iterations for curl https://google.com
# .....
# Averaged 63.8024 ms in 10 iterations
#!/bin/sh
iterations=$1
url=$2
echo "Running $iterations iterations for curl $url"
totaltime=0.0
for run in $(seq 1 $iterations)
do
time=$(curl $url -s -o /dev/null -w "%{time_starttransfer}\n")
totaltime=$(echo "$totaltime" + "$time" | bc)
done
avgtimeMs=$(echo "scale=4; 1000*$totaltime/$iterations" | bc)
echo "Averaged $avgtimeMs ms in $iterations iterations"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment