Website speed benchmarking from command line
I wanted to test the speed difference of a Wordpress blog before and after WP-Supercache was set up. Here's how I did it, using just bash, curl, sed and awk:
Basically, time how long it takes to get the website about 100 times, and get the average. For my non-cached site on a low end Linode VPS this took between 0.8 and 1.3 seconds. After setting up WP-Supercache, the average time dropped to under 0.5 seconds -- a 40-60% improvement in pure speed. So, WP-Supercache works great!
Bonus: I ran the same script to load the page 100 times while running top on the server and eyeballing the numbers. The results were impressive - with no caching there were 2-5 apache processes running, each taking about 5% memory and 8% cpu. That is a recipe for disaster and the site would probably last about 2 seconds before dying under the Digg effect. With WP-Supercache fully enabled, there was only a single apache process running, consuming 5% memory and virtually no cpu.
If you're interested in more detail about how the command line stuff works, here is a brief explanation. The first loop runs 100 times, piping the output of time to a text file. The curl command itself (the one being timed) is executed in a subshell and its output is discarded). The second loop is identical, just saving to a different file to record the new speeds.
The last line is meant to be saved as an executable file so it is convenient for reuse. It takes two arguments, a file and the type of time you want the average of (from the time command; you want "real"). So the script prints out the file with cat, separates the actual time value nicely with a search-and-replace regular expression with sed, then uses awk to find the average by looking at the correct times (real/user/sys), counting those lines and summing the total, and dumping the average when complete.
It took me longer to write this brief post than it did to come up with that script. Real alternatives are ab and httperf, but this worked for me and I didn't have to read any man pages.