fbpx

Measuring WordPress speed

Written: 9.12.2017 Updated: 27.1.2020

Improving the performance of WordPress sites is a popular topic among WordPress developers. E-commerce owners know that faster websites mean more conversions and more sales. Everybody hates to wait for pages that take long to load. However, the knowledge of how to correctly improve the performance of WordPress sites is still surprisingly scarce.

The most basic and most central skill is how to measure the current speed of a WordPress site. Developers who don’t know how to measure the speed of their code or site, have a slim chance of making anything faster. Trying our 10 things that might (and mostly might not) improve a site is a waste of time and depends on the luck of striking something that matters.

For WordPress, the most basic measurement is to time how long it takes for PHP to produce the HTML output. The most straightforward way to test any site anywhere is to use the command-line tool curl. Just install the package (e.g. apt install curl in Debian based Linux machines) and run curl while printing the time_total value:

curl -s -o /dev/null -w "%{time_total}\n" https://example.com/
0.123

This means that the site took 123 milliseconds to load from the server to the machine running curl. To avoid the network lag between the server and your own computer, simply log into the server using ssh and run the curl to cut out all network hops in the middle.

If the WordPress site is running in a professional server environment, there will be some caching layers between the site and the world outside. This caching layer will deliver the HTML content much faster than PHP would. To make sure you always get the response all the way from PHP, you need to burst the cache layer using the No-Pragma header (this is the same header your browser emits when you press Ctrl+F5).

curl -s -o /dev/null -w "%{time_total}\n" -H "Pragma: no-cache" https://example.com/

Some times the PHP execution will not be identical on every page load, or the server environment might be noisy. To make multiple measurements and get the average response time, you can use some for and awk scripting:

export LC_NUMERIC=C
for i in {1..20}
do 
 curl -so /dev/null -w "%{time_total}\n" https://example.com/
done | awk '{ sum += $1; n++; print $1 } END { if (n > 0) print "AVG: " sum / n; }'

0.209
0.107
0.152
AVG: 0.1378

Finally, if you have SSH access to the server and wp-cli is installed, you can disable one plugin at a time with this handy bash script snippet to see if there is a single plugin that drastically affects the PHP page load time:

for p in $(wp plugin list --fields=name --status=active)
do
  echo $p
  wp plugin deactivate --skip-plugins $p
  for i in {1..5}
  do
    curl -so /dev/null -w "%{time_total}\n" \
    -H "Pragma: no-cache" https://example.com/
  done
  wp plugin activate $p 
done

We like to preach about WordPress performance. Making websites faster does not only make the world run more smoothly, but it actually also saves computer processing power and electricity, and thus helps to save the world!

Below are the slides from WordCamp Athens where you can find more information about the topic.

3 comments on “Measuring WordPress speed”

Leave a comment

Otto Kekäläinen

CEO

Search Seravo.com

Categories

More reading

Webinar: Dismantle WordPress Performance Bottlenecks

27.5.2020

We recently hosted a webinar focusing on cache, more specifically what a WordPress developer should know about caching. One of […]

Everything You Go Through, Grows You – The Story of Robit

22.5.2020

In this video, you’ll hear Daniel Palander, Process Development Manager of Robit talking about how the company that started back […]

PCIe-NVMe – Faster than SSD

14.5.2020

Most people working with computers have first-hand experience of working with solid-state drives that are dramatically faster than the traditional […]