ExpressionEngine - measuring performance during development

When you’re developing an ExpressionEngine site and you get into optimisation there are some often overlooked Standard Global Variables that can come in useful, these variables give you performance information about the current page being viewed.

The variables

elapsed_time - how quick the page renders (in seconds)
total_queries - the number of queries EE has to make to create the page
gzip_mode - “on” or “off”
app_version - the EE version you’re running
app_build - the EE version build date

Adding the code

I like to create a simple DIV element with the variable in it:

{if logged_in}
<div id="admin">
Page render time{elapsed_time} sec 
Queries{total_queries} 
Gzip{gzip_mode}  
EE version{app_version} build {app_build}
</div>
{/if} 

Note that it’s only viewable if you’re logged in (if logged_in), you could restrict this to certain member groups such as Super Admins if you wanted.

Normally I just place the code in a Snippet called sn_admin, then add the snippet straight after the BODY tag, though you could add it wherever suits:

<body>
{sn_admin} 

Then add some light styling:

#admin {
width96%; 
padding2%; 
background#000; 
color#FFF; 
text-aligncenter
clearboth

Now when you’re logged into the CP and view front end pages you should see the variable values. When you start optimising (such as caching templates) you’ll see the numbers change on page refresh!

You can find a full list of Standard Global Variables at http://expressionengine.com/user_guide/templates/globals/single_variables.html