method_profiler 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'method_profiler/report'
|
2
|
+
require 'method_profiler/core_ext/object'
|
2
3
|
|
3
4
|
require 'benchmark'
|
4
5
|
|
@@ -73,7 +74,8 @@ module MethodProfiler
|
|
73
74
|
def profile(method, singleton = false, &block)
|
74
75
|
method_name = singleton ? ".#{method}" : "##{method}"
|
75
76
|
result = nil
|
76
|
-
elapsed_time = benchmark(result, &block)
|
77
|
+
elapsed_time, result = benchmark(result, &block)
|
78
|
+
elapsed_time = elapsed_time.to_s.match(/\(\s*([^\)]+)\)/)[1].to_f
|
77
79
|
@data[method_name] << elapsed_time
|
78
80
|
result
|
79
81
|
end
|
@@ -85,11 +87,11 @@ module MethodProfiler
|
|
85
87
|
total_calls = records.size
|
86
88
|
average = records.reduce(:+) / total_calls
|
87
89
|
results << {
|
88
|
-
method
|
89
|
-
min
|
90
|
-
max
|
91
|
-
average
|
92
|
-
total_calls
|
90
|
+
:method => method,
|
91
|
+
:min => records.min,
|
92
|
+
:max => records.max,
|
93
|
+
:average => average,
|
94
|
+
:total_calls => total_calls
|
93
95
|
}
|
94
96
|
end
|
95
97
|
|
@@ -99,7 +101,8 @@ module MethodProfiler
|
|
99
101
|
private
|
100
102
|
|
101
103
|
def benchmark(result, &block)
|
102
|
-
Benchmark.measure { result = block.call }
|
104
|
+
elapsed_time = Benchmark.measure { result = block.call }
|
105
|
+
return elapsed_time, result
|
103
106
|
end
|
104
107
|
end
|
105
108
|
end
|
@@ -68,20 +68,20 @@ module MethodProfiler
|
|
68
68
|
"MethodProfiler results for: #{@obj}",
|
69
69
|
Hirb::Helpers::Table.render(
|
70
70
|
to_a,
|
71
|
-
headers
|
72
|
-
method
|
73
|
-
min
|
74
|
-
max
|
75
|
-
average
|
76
|
-
total_calls
|
71
|
+
:headers => {
|
72
|
+
:method => "Method",
|
73
|
+
:min => "Min Time",
|
74
|
+
:max => "Max Time",
|
75
|
+
:average => "Average Time",
|
76
|
+
:total_calls => "Total Calls"
|
77
77
|
},
|
78
|
-
fields
|
79
|
-
filters
|
80
|
-
min
|
81
|
-
max
|
82
|
-
average
|
78
|
+
:fields => [:method, :min, :max, :average, :total_calls],
|
79
|
+
:filters => {
|
80
|
+
:min => :to_milliseconds,
|
81
|
+
:max => :to_milliseconds,
|
82
|
+
:average => :to_milliseconds
|
83
83
|
},
|
84
|
-
description
|
84
|
+
:description => false
|
85
85
|
)
|
86
86
|
].join("\n")
|
87
87
|
end
|
data/method_profiler.gemspec
CHANGED
@@ -11,6 +11,14 @@ describe MethodProfiler::Profiler do
|
|
11
11
|
petition.should_not respond_to(:foo_with_profiling_with_profiling)
|
12
12
|
end
|
13
13
|
|
14
|
+
it "class methods should properly return values" do
|
15
|
+
Petition.guys.should == "sup"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "instance method should properly return values" do
|
19
|
+
petition.baz.should == "blah"
|
20
|
+
end
|
21
|
+
|
14
22
|
describe "#report" do
|
15
23
|
it "returns a new Report object" do
|
16
24
|
profiler.report.should be_an_instance_of MethodProfiler::Report
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_profiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hirb
|
16
|
-
requirement: &
|
16
|
+
requirement: &70256884010560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.6.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70256884010560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70256884010160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70256884010160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: simplecov
|
38
|
-
requirement: &
|
38
|
+
requirement: &70256884009700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70256884009700
|
47
47
|
description: MethodProfiler observes your code and generates reports about the methods
|
48
48
|
that were run and how long they took.
|
49
49
|
email:
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- README.md
|
59
59
|
- Rakefile
|
60
60
|
- lib/method_profiler.rb
|
61
|
+
- lib/method_profiler/core_ext/object.rb
|
61
62
|
- lib/method_profiler/hirb.rb
|
62
63
|
- lib/method_profiler/profiler.rb
|
63
64
|
- lib/method_profiler/report.rb
|