SimpleTimeMeasure Build Status

SimpleTimeMeasure is a ruby gem that allows measuring methods without having to alter code of the methods themselves.

Requirements

Ruby 2.1 or later (it uses Module#prepend introduced in Ruby 2.0 and Process::CLOCK_MONOTONIC introduced in Ruby 2.1)

Installation

Add this line to your application's Gemfile:

gem 'simple_time_measure'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_time_measure

Usage

  class DummyClass
    include SimpleTimeMeasure

    measure_instance_method :test do |result|
      p "instance method :test #{result}"
    end

    measure_class_method :test2 do |result|
      p "class method :test2 #{result}"
    end

    def test
      sleep(1)
      1
    end

    def self.test2
      sleep(1)
      2
    end
  end

  DummyClass.new.test
  "instance method :test {:cpu_time=>60, :wall_time=>1000227, :idle_time=>1000167}"
  => 1

  DummyClass.test2
  "class method :test2 {:cpu_time=>61, :wall_time=>1000214, :idle_time=>1000153}"
  => 2

cpu, wall and idle time are in microseconds

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dbackowski/simple_time_measure. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the SimpleTimeMeasure project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.