There’s a new Rails benchmarking plugin in town – BenchmarkForRails. Why? Because with Rails’ benchmarks I never knew how long the request was really taking, including filters and sessions and all that jazz. And because building queries can take longer than executing them, which makes Rails’ DB benchmark somewhat, um, misleading.
This plugin introduces benchmarking for:
- the entire process lifecycle
- session initialization
- before filters (as a group)
- after filters (as a group)
- time spent in ActiveRecord::Base.find
- time spent in a respond_to block
Furthermore, it makes adding more benchmarks incredibly easy. Just follow these simple steps:
- Find the method you want to benchmark. Note the class/module, the method name, and whether it’s an instance or class method. Let’s suppose you want to benchmark the link_to helper in ActionView::Helpers::UrlHelper.
- In your config somewhere (e.g. initializers/custom_benchmarks.rb), tell BenchmarkForRails to watch that method, like so:
BenchmarkForRails.watch(
"link_to calls",
ActionView::Helpers::UrlHelper,
:link_to
)
And some sample output, from the log file:
- [0.0489] GET SiteController#index ---- 0.0184 session startup 0.0013 activerecord find 0.0001 before filters 0.0000 after filters 0.0000 respond_to block -------------------- BenchmarkForRails -
Errata:
- This has only been tested with Rails 2.0 RC1. I really really doubt it works in Rails 1.2.
- Subversion URL is http://benchmarkforrails.googlecode.com/svn/trunk