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 class=“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 partial template called part_admin, then add the template tag straight after the BODY tag, though you could add it wherever suits:

<body>
{part_admin}

Then add some light styling:

.admin {
width: 96%; 
padding: 2%; 
background: #000; 
color: #FFF; 
text-align: center; 
clear: both; 
}

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 https://docs.expressionengine.com/latest/templates/globals/single_variables.html

You might also like

You don't know unless you ask

Contact me today