An open API service indexing awesome lists of open source software.

https://github.com/dbackowski/simple_time_measure

SimpleTimeMeasure is a ruby gem that allows measuring methods without having to alter code of the methods themselves.
https://github.com/dbackowski/simple_time_measure

gem measure ruby time

Last synced: 7 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# SimpleTimeMeasure [![Build Status](https://travis-ci.org/dbackowski/simple_time_measure.svg?branch=master)](https://travis-ci.org/dbackowski/simple_time_measure)

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:

```ruby
gem 'simple_time_measure'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_time_measure

## Usage

```ruby
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](https://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](http://contributor-covenant.org) code of conduct.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## 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](https://github.com/dbackowski/simple_time_measure/blob/master/CODE_OF_CONDUCT.md).