Insites Docs Developers guide Best PracticesBack-End PerformanceMeasuring the Execution Time of Liquid Code

Measuring the Execution Time of Liquid Code

Last updated on June 26, 2024.

This guide shows you how to measure the execution time of Liquid code fragments using the filter. You can use this method to find out which part of a page you can modify to improve execution times.

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 and Liquid filters and how to create application logs.

  • Development Workflow
  • Get Started
  • Liquid filter: time_diff
  • Liquid filter: to_time
  • Creating Application Logs
  • Steps

    Measuring the execution time of Liquid code fragments using the Liquid filter is a three-step process:

    • 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:

    Two items could potentially cause results to be displayed slowly:

    1. GraphQL query
    2. for loop rendering records

    Step 2: Adding the 'to_time' and 'time_diff' filters

    Use the and filters to measure execution times.
    The and variables store partial execution times in milliseconds. The variable stores the overall execution time of the code block.

    Step 3: Checking results in the logs

    Test results are sent to your instance log stream and can be accessed by using the tool.

    Next Steps

    Congratulations! You now know how to measure the execution time of Liquid code fragments using the filter. You may visit another tutorial that uses this method for testing two different solutions: Loading Related Records

    Have a suggestion for this page?

    Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.