# How to Benchmark Rails Views

*Published on September 21, 2022*

---


If your Rails application is taking longer than expected to load a specific page, use Active Support's&nbsp;[Benchmarkable](https://api.rubyonrails.org/classes/ActiveSupport/Benchmarkable.html)&nbsp;module to measure the code execution time in your view templates.

Here's the typical code you'd write to display the posts on your blog.

```ruby
<% @posts.each do |post| %>
  <%= render post %>
<% end %>
```

Let's say your home page, which displays the posts, is taking too long to load. To find how long it takes to execute this code, simply wrap it in the&nbsp;`benchmark`&nbsp;method.

```ruby
<% benchmark 'Display posts' do %>
  <% @posts.each do |post| %>
    <%= render post %>
  <% end %>
<% end %>
```

When you reload the above view, Rails will print the time taken to execute the above template with the label you provided.

![code-5.png](https://writesoftwarewell.com/media/f8fqis3e1tv3qp5lmtjm49srmtey.png "Benchmark")

Behind the scenes, the Benchmarkable module uses the&nbsp;`Benchmark`&nbsp;class provided by the Ruby standard library, which we saw in my earlier post,&nbsp;[How to Benchmark Ruby Code](/how-to-benchmark-ruby-code).

So this is how you can benchmark your Rails views. I hope you learned something new. I sure did.&nbsp;[Let me know](mailto:akshay.khot@hey.com)&nbsp;if you liked this post or have any feedback. I look forward to hearing from you.

