Cacomania: Measuring the average website response time with cURL

Cacomania

Measuring the average website response time with cURL

Guido Krömer - 5. September 2012 - Tags: , , ,

cURL is really useful Measuring web response time, with some bash scripting it can be used to calculate the average response time.

Because of the lack of floating-point arithmetic in bash, in comparison to zsh or ksh, bc has to be used to calculate the average time.

#!/bin/bash

URL="$1"
MAX_RUNS="$2"
SUM_TIME="0"

i="0"
while [ $i -lt $MAX_RUNS ]; do
  TIME=`curl $URL -o /dev/null -s -w %{time_total}`  
  TIME="${TIME/,/.}"
  SUM_TIME=`echo "scale=5; $TIME + $SUM_TIME" | bc`
  i=$[$i+1]
done

TIME_AVERAGE=`echo "scale=5; $SUM_TIME / $MAX_RUNS" | bc`
echo "Sum: $SUM_TIME"
echo "Avg: $TIME_AVERAGE"

This is a simple test with one thousand calls on two different implementations of the same website, one in plain (no use of OOP) PHP and one as MVC Application using the Zend Framework.

[caco@ThinkPad-T61 ~]# ./web_test.sh http://phpplain 1000
Sum: 6.970
Avg: .00697
[caco@ThinkPad-T61 ~]# ./web_test.sh http://phpzend 1000
Sum: 9.461
Avg: .00946

Have fun using and improving this small script.