Developers · Best Practices
Measuring the Execution Time of Liquid Code
Last updated 7 November 2026
This guide shows you how to measure the execution time of Liquid code fragments using the
Prerequisites
This guide is an advanced tutorial. To follow it, you must understand basic Insites concepts such as the topics in the Get Started section, the
Steps
Measuring the execution time of Liquid code fragments using the
- Step 1: Identifying measuring points
- Step 2: Adding the 'to_time' and 'time_diff' filters
- Step 3: Checking results in the logs
Step 1: Identifying measuring points
Locate the part of the code you want to measure. Take a look at this sample snippet:
{% graphql g = "modules/n_plus_one/n1_programmers" %}
{% for programmer in g.programmers.results %}
<tr>
<td>{{ programmer.properties.email }}</td>
<td>{{ programmer.properties.title }}</td>
<td>{{ programmer.company.properties.name }}</td>
</tr>
{% endfor %}Two items could potentially cause results to be displayed slowly:
- GraphQL query
- for loop rendering records
Step 2: Adding the 'to_time' and 'time_diff' filters
Use the
The
{% liquid
assign __start = "now" | to_time
graphql g = "modules/n_plus_one/n1_programmers"
assign __graph = "now" | to_time
%}
{% for programmer in g.programmers.results %}
<tr>
<td>{{ programmer.properties.email }}</td>
<td>{{ programmer.properties.title }}</td>
<td>{{ programmer.company.properties.name }}</td>
</tr>
{% endfor %}
{% liquid
assign __render = "now" | to_time
assign _total_duration = __start | time_diff: __render
assign _graph_duration = __start | time_diff: __graph
assign _render_duration = __graph | time_diff: __render
log _total_duration, type: "benchmark-total"
log _graph_duration, type: "benchmark-graph"
log _render_duration, type: "benchmark-render"
%}Step 3: Checking results in the logs
Test results are sent to your instance log stream and can be accessed by using the
Next Steps
Congratulations! You now know how to measure the execution time of Liquid code fragments using the