Baseline Web Page Testing using Curl
Wednesday, October 17th, 2007I wanted a way to compare the page load times of my website on the old server and on the new server where I’m moving it.
I found an easy way to do this is to use curl. I was inspired by this article, but I improve on it by providing examples that work!
Here are the steps to getting a nice tabular file that shows load time information across a series of URL’s. (Only tested on Ubuntu.)
First I installed curl:
sudo apt-get install curl
Next I made a file called test_config.txt. Here are the contents:
-A "Mozilla/4.0 (compatible; cURL 7.10.5-pre2; Linux 2.4.20)" -L -w @logformat.txt -D headers.txt -H "Pragma: no-cache" -H "Cache-control: no-cache" -H "Connection: close" url="http://foo.com/" url="http://foo.members.linode.com/" url="http://foo.com/utility/Text_Diff" url="http://foo.com/" url="http://foo.members.linode.com/" url="http://foo.com/utility/Text_Diff"
The inspiration article explains a bit about what’s going on here.
Next I made a file called logformat.txt which you can see is referenced in test_config.txt above. Here are the contents of that file:
\\n
%{url_effective}\\t%{http_code}\\t%{content_type}\\t%{time_total}\\t%{time_namelookup}\\t%{time_connect}\\t%{time_starttransfer}\\t%{size_download}\\n
\\n
Again the inspiration article explains a bit about what's going on with this.
Finally we're ready to run curl. The trick here is that curl insists on outputting the contents of the web pages along with the statistics we want so we pipe it through grep as so (I'm assuming you're in the directory with the files we just made.):
$ curl -K test_config.txt | grep -i -r "^http://.*$" >> final_output.txt
This whole command runs curl using our configuration files, passes the output to grep, which then pulls out only the lines starting with http:// and outputs that to the file final_output.txt.