method_profiler 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,11 +21,17 @@ class MethodProfiler
21
21
 
22
22
  def report
23
23
  [
24
- "MethodProfiler results for:",
25
- @obj.to_s,
24
+ "MethodProfiler results for: #{@obj}",
26
25
  Hirb::Helpers::Table.render(
27
26
  final_data,
28
- headers: ["Method", "Average Time", "Total Calls"],
27
+ headers: {
28
+ method: "Method",
29
+ min: "Min Time",
30
+ max: "Max Time",
31
+ average: "Average Time",
32
+ total_calls: "Total Calls"
33
+ },
34
+ fields: [:method, :min, :max, :average, :total_calls],
29
35
  description: false
30
36
  )
31
37
  ].join("\n")
@@ -75,10 +81,23 @@ class MethodProfiler
75
81
  data.each do |method, records|
76
82
  total_calls = records.size
77
83
  average = records.reduce(:+) / total_calls
78
- final_data << [method, '%f ms' % (average * 1000), total_calls]
84
+ final_data << {
85
+ method: method,
86
+ min: records.min,
87
+ max: records.max,
88
+ average: average,
89
+ total_calls: total_calls
90
+ }
91
+ end
92
+ final_data.sort! { |a, b| b[:average] <=> a[:average] }
93
+ final_data.each do |record|
94
+ [:min, :max, :average].each { |k| record[k] = to_ms(record[k]) }
79
95
  end
80
- final_data.sort! { |a, b| b[1] <=> a[1] }
81
96
  final_data
82
97
  end
83
98
  end
99
+
100
+ def to_ms(seconds)
101
+ "%.3f ms" % (seconds * 1000)
102
+ end
84
103
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "method_profiler"
5
- s.version = "0.0.1"
5
+ s.version = "0.1.0"
6
6
  s.authors = ["Jimmy Cuadra"]
7
7
  s.email = ["jimmy@jimmycuadra.com"]
8
8
  s.homepage = "https://github.com/change/method_profiler"
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: 0.0.1
4
+ version: 0.1.0
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-01 00:00:00.000000000 Z
12
+ date: 2012-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hirb
16
- requirement: &70119481195160 !ruby/object:Gem::Requirement
16
+ requirement: &70179117063300 !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: *70119481195160
24
+ version_requirements: *70179117063300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70119481194080 !ruby/object:Gem::Requirement
27
+ requirement: &70179117084460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70119481194080
35
+ version_requirements: *70179117084460
36
36
  description: MethodProfiler observes your code and generates reports about the methods
37
37
  that were run and how long they took.
38
38
  email: