benchmark_methods 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8900e5fcc95812b667857a13ad0e468a52a26c4
4
+ data.tar.gz: 9ab8178b3e2b04edecf9fc0057eee16625f3af44
5
+ SHA512:
6
+ metadata.gz: da0d043053fa6e955933984285756a4e8922e6479db9bb975320bfc05fc46d72cfe56cc3cc7481545a8b3047546b313a5ed82dc5acf6c07b5e94abadb23a72a9
7
+ data.tar.gz: cb49af1a6d976363f058326d40e0d228f8d32bc3765eb456af21e8598a32b93be719388974c9294ea632b1953d6a38ec369996b0dcdaa6a84c564b6da86e95b9
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - "2.0"
5
+ - "2.1"
6
+ - "2.2"
7
+ - ruby-head
8
+
9
+ before_install: "gem install bundler && gem install rspec"
10
+
11
+ cache: bundler
12
+
13
+ script: bundle exec rspec
14
+
15
+ bundler_args: --without development --jobs=3 --retry=3 --path=../vendor/bundle
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in benchmark_methods.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
7
+ gem 'rspec'
8
+ gem 'rspec-core'
9
+ gem 'sqlite3'
10
+ gem 'activerecord'
11
+ gem 'simplecov', :require => false, :group => :test
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Igor Kasyanchuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # BenchMarkMethods
2
+
3
+ Measure and benchmark execution time of your ruby methods. Forgot about `Time.now - t` solution. Use `benchmark` to see how much time it takes to execute your method.
4
+
5
+ [![Build Status](https://travis-ci.org/igorkasyanchuk/benchmark_methods.svg?branch=master)](https://travis-ci.org/igorkasyanchuk/benchmark_methods)
6
+
7
+ Sample or usage:
8
+
9
+ [![Sample](https://raw.githubusercontent.com/igorkasyanchuk/benchmark_methods/master/benchmark_methods.png)](https://raw.githubusercontent.com/igorkasyanchuk/benchmark_methods/master/benchmark_methods.png)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'benchmark_methods'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install benchmark_methods
26
+
27
+
28
+ **Note: works only for Ruby 2+**
29
+
30
+ ## Usage
31
+
32
+ Let's say you have sample model `User` with two methods:
33
+
34
+
35
+ ```ruby
36
+ class User < ActiveRecord::Base
37
+ include BenchmarkMethods
38
+
39
+ benchmark :generate_report
40
+ cbenchmark :import_users
41
+
42
+ def generate_report
43
+ report = reports.create(name: 'My Report')
44
+ report.add_db_data
45
+ report.generate
46
+ report
47
+ end
48
+
49
+ def self.import_users(csv)
50
+ CSV.parse(csv) do |row|
51
+ process_import_user(row)
52
+ end
53
+ end
54
+ end
55
+ ```
56
+
57
+ **Sample Output:**
58
+
59
+ ```
60
+ --> User.create_user_and_comments
61
+ user system total real
62
+ 0.010000 0.000000 0.010000 ( 0.006721)
63
+ --> User create_test_friend
64
+ user system total real
65
+ 0.000000 0.000000 0.000000 ( 0.000681)
66
+ ```
67
+
68
+ Gem allows to **benchmark ruby methods** (instance and class methods).
69
+
70
+ ### Functionality
71
+
72
+ `include BenchmarkMethods` - put in your classes, models to add support for benchmarks
73
+
74
+ `benchmark :method_name` - benchmark your insatance method.
75
+
76
+ `cbenchmark :method_name` - benchmark your class method.
77
+
78
+ ## Plans
79
+
80
+ * Add more Specs
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
85
+
86
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
+
88
+ ## Contributing
89
+
90
+ 1. Fork it ( https://github.com/[my-github-username]/benchmark_methods/fork )
91
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
92
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
93
+ 4. Push to the branch (`git push origin my-new-feature`)
94
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'benchmark_methods/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "benchmark_methods"
8
+ spec.version = BenchmarkMethods::VERSION
9
+ spec.authors = ["Igor Kasyanchuk"]
10
+ spec.email = ["igorkasyanchuk@gmail.com"]
11
+
12
+ spec.summary = %q{Measure and benchmark execution time of your ruby methods}
13
+ spec.description = %q{Measure and benchmark execution time of your ruby methods. Forgot about `Time.now - t` solution. Use `benchmark` to see how much time it take sto execute your method.}
14
+ spec.homepage = "https://github.com/igorkasyanchuk/benchmark_methods"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "activerecord", "> 0"
25
+ spec.add_development_dependency "rspec", "> 0"
26
+ spec.add_development_dependency "pry", "> 0"
27
+ spec.add_development_dependency "simplecov", "> 0"
28
+ spec.add_development_dependency 'sqlite3', "> 0"
29
+ end
Binary file
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "benchmark_methods"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,76 @@
1
+ require 'securerandom'
2
+ require 'benchmark'
3
+ require 'benchmark_methods/version'
4
+
5
+ module BenchmarkMethods
6
+
7
+ def self.included(base_klass)
8
+ base_klass.extend(ClassMethods)
9
+ interceptor = const_set("#{base_klass.name.demodulize}Interceptor", Module.new)
10
+ base_klass.send(:prepend, interceptor)
11
+ end
12
+
13
+ def self.log(report)
14
+ if Object.const_defined?("Rails")
15
+ Rails.logger.debug(" --> #{report.label}")
16
+ Rails.logger.debug(Benchmark::CAPTION)
17
+ Rails.logger.debug(report)
18
+ else
19
+ puts(" --> #{report.label}")
20
+ puts(Benchmark::CAPTION)
21
+ puts(report)
22
+ end
23
+ end
24
+
25
+ def self.measure(label, &block)
26
+ t0, r0 = Process.times, Time.now
27
+ result = yield
28
+ t1, r1 = Process.times, Time.now
29
+ report = Benchmark::Tms.new(t1.utime - t0.utime,
30
+ t1.stime - t0.stime,
31
+ t1.cutime - t0.cutime,
32
+ t1.cstime - t0.cstime,
33
+ r1 - r0,
34
+ label)
35
+ BenchmarkMethods::log(report)
36
+ result
37
+ end
38
+
39
+ module ClassMethods
40
+
41
+ def cbenchmark(*cmethods)
42
+ interceptor = const_get("#{name.demodulize}Interceptor")
43
+ klass = const_get(name)
44
+ helper = const_set("BenchmarkMethods#{SecureRandom.hex}Helper", Module.new)
45
+ cmethods.each do |method_name|
46
+ interceptor.module_eval do
47
+ helper.send :define_singleton_method, :prepended do |base|
48
+ define_method(method_name) do |*args, &block|
49
+ BenchmarkMethods::measure("#{klass}.#{method_name}") do
50
+ super(*args, &block)
51
+ end
52
+ end
53
+ end
54
+ (class << klass; self; end).module_eval do
55
+ prepend(helper)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def benchmark(*cmethods)
62
+ interceptor = const_get("#{name.demodulize}Interceptor")
63
+ klass = const_get(name)
64
+ cmethods.each do |method_name|
65
+ interceptor.module_eval do
66
+ define_method(method_name) do |*args, &block|
67
+ BenchmarkMethods::measure("#{klass} #{method_name}") do
68
+ super(*args, &block)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module BenchmarkMethods
2
+ VERSION = "0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benchmark_methods
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Igor Kasyanchuk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Measure and benchmark execution time of your ruby methods. Forgot about
112
+ `Time.now - t` solution. Use `benchmark` to see how much time it take sto execute
113
+ your method.
114
+ email:
115
+ - igorkasyanchuk@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - benchmark_methods.gemspec
129
+ - benchmark_methods.png
130
+ - bin/console
131
+ - bin/setup
132
+ - lib/benchmark_methods.rb
133
+ - lib/benchmark_methods/version.rb
134
+ homepage: https://github.com/igorkasyanchuk/benchmark_methods
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.6
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Measure and benchmark execution time of your ruby methods
158
+ test_files: []