Ruby on Rails
BenchmarkingRails

There are a number of tools and approaches for benchmarking your Rails application. This page will outline some of them.

Rails-analyzer

RailsAnalyzer has benchmarking tools as well as tools for log analysis and status monitoring.

script/benchmarker and profiler

Rails 0.12 (19th April, 2005) Added the BenchmarkerScript and the ProfilerScript to easily benchmark1 and profile Rails code from the command line.

TestBench — benchmark nearly anything

Florian Weber put together some code by that does benchmarking as an extension of test/unit . It also produces a nice html report (see this teaser post for a screen)

This approach allows benchmarking1 to be either very narrow/specific (such as a single method) or very broad/inclusive (such as responding to a request and rendering a view).

Benchmark views rendering

Rails 0.13 (6th July, 2005) introduced BenchmarkHelper to measure the execution time of block in a view1. Read the BenchmarkHelper API docs for usage details.

Benchmark with ActiveRecord

All classes that inherit from ActiveRecord::Base have a benchmark method1 that logs and benchmarks multiple statements in a single block.

Benchmark controllers with a filter

Example:


class WeblogController < ActionController::Base
   around_filter BenchmarkingFilter.new
   
   # Before this action is performed, BenchmarkingFilter#before(controller) is executed
   def index
   end
   # After this action has been performed, BenchmarkingFilter#after(controller) is executed
 end
 
 class BenchmarkingFilter
   def initialize
     @runtime
   end
   
   def before
     start_timer
   end
   
   def after
     stop_timer
     report_result
   end
 end

See the complete filter documentation for more details


1 Rails benchmarking is based on the Benchmark Ruby standard library.