benchmark_method 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +1 -0
- data/benchmark_method.gemspec +19 -0
- data/benchmark_method_test.rb +25 -0
- data/lib/benchmark_method.rb +28 -0
- data/lib/benchmark_method/version.rb +3 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 AvnerCohen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# ::BenchmarkMethod
|
2
|
+
|
3
|
+
Wrap any existing method with a measurment for total execution time. result of total time will be logged to assist on profiling running code
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'benchmark_method'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install benchmark_method
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
````ruby
|
22
|
+
class MyClass
|
23
|
+
|
24
|
+
def long_running_method
|
25
|
+
self.content.map {|i| i.takes_forever! }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
````
|
30
|
+
|
31
|
+
Should simple be changed to:
|
32
|
+
|
33
|
+
````ruby
|
34
|
+
class MyClass
|
35
|
+
|
36
|
+
include BenchmarkMethod
|
37
|
+
|
38
|
+
def long_running_method
|
39
|
+
self.content.map {|i| i.takes_forever! }
|
40
|
+
end
|
41
|
+
|
42
|
+
measure :long_running_method
|
43
|
+
end
|
44
|
+
````
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'benchmark_method/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "benchmark_method"
|
8
|
+
gem.version = BenchmarkMethod::VERSION
|
9
|
+
gem.authors = ["AvnerCohen"]
|
10
|
+
gem.email = ["israbirding@gmail.com"]
|
11
|
+
gem.description = %q{Wrap any existing method with a measurment total execution time. result of total time will be logged to assist on profiling running code}
|
12
|
+
gem.summary = %q{Benchmark your ruby methods and profile it easily.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
gem "benchmark_method"
|
2
|
+
|
3
|
+
require 'benchmark_method'
|
4
|
+
|
5
|
+
class BenchmarkMethodTest
|
6
|
+
include BenchmarkMethod
|
7
|
+
|
8
|
+
def long_running
|
9
|
+
ran = (0..10000000)
|
10
|
+
total = 0
|
11
|
+
ran.collect { |i| total +=i * 2 }
|
12
|
+
puts "Total number is #{total}"
|
13
|
+
end
|
14
|
+
measure :long_running
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def run!
|
20
|
+
kls = BenchmarkMethodTest.new
|
21
|
+
kls.long_running
|
22
|
+
p "Done !!"
|
23
|
+
end
|
24
|
+
|
25
|
+
run!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require "benchmark_method/version"
|
3
|
+
require 'benchmark'
|
4
|
+
|
5
|
+
module BenchmarkMethod
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.class_eval do
|
9
|
+
extend ClassMethods
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def measure(method)
|
15
|
+
alias_method "measure_#{method}", method
|
16
|
+
define_method(method) do |*args, &block|
|
17
|
+
method_results = nil
|
18
|
+
results_ms = Benchmark.realtime do
|
19
|
+
method_results = self.send "measure_#{method}", *args, &block
|
20
|
+
end
|
21
|
+
str = "BenchmarkMethod::#{$$}::#{method.to_s}::Total Execution time #{(results_ms * 1000).round(2)}(ms)"
|
22
|
+
defined?(Rails) ? (Rails.logger.error str) : (puts str) #hackish, i guess
|
23
|
+
method_results
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: benchmark_method
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- AvnerCohen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Wrap any existing method with a measurment total execution time. result
|
15
|
+
of total time will be logged to assist on profiling running code
|
16
|
+
email:
|
17
|
+
- israbirding@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- benchmark_method.gemspec
|
28
|
+
- benchmark_method_test.rb
|
29
|
+
- lib/benchmark_method.rb
|
30
|
+
- lib/benchmark_method/version.rb
|
31
|
+
homepage: ''
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.24
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Benchmark your ruby methods and profile it easily.
|
55
|
+
test_files: []
|
56
|
+
has_rdoc:
|