Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Benchmeth

The super easy way to benchmark methods in a live application

class Person
  def compute
    # boom
  end
  benchmark :compute
end

Works with class methods, too

class Person
  def self.compute
    # yolo
  end
  class << self
    benchmark :compute
  end
end

Installation

Add this line to your application’s Gemfile:

gem 'benchmeth'

How to Use

By default, benchmark data is written to stdout in the following format:

compute : 1000 ms

but you can easily do whatever you want with it.

Benchmeth.on_benchmark do |method_name, seconds|
  puts "#{method_name} took #{seconds} seconds!"
end

To call a method without benchmarking, append _without_benchmark to the name.

ActiveSupport Notifications

You can switch to ActiveSupport notifications with:

Benchmeth.use_notifications = true

And subscribe with:

ActiveSupport::Notifications.subscribe "benchmark.benchmeth" do |*args|
  event = ActiveSupport::Notifications::Event.new(*args)
  puts "%s : %d ms" % [event.payload[:name], event.duration]
end

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/benchmeth.git
cd benchmeth
bundle install
bundle exec rake test

About

The super easy way to benchmark methods in a live application

Resources

License

Packages

No packages published

Languages