rubyperf 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 1.3.2
data/lib/perf/meter.rb CHANGED
@@ -417,7 +417,7 @@ protected
417
417
  def method_missing(method_sym, *arguments, &block)
418
418
  if method_sym.to_s =~ /^report_(.*)$/
419
419
  klass=Object.const_get("Perf").const_get("ReportFormat#{camelize($1)}")
420
- return klass.new.format(self) if klass
420
+ return klass.new.format(self,arguments[0]) if klass
421
421
  end
422
422
  super
423
423
  end
@@ -26,6 +26,7 @@ module Perf
26
26
  #
27
27
 
28
28
  def format(perf,options={})
29
+ options||={}
29
30
  options[:max_count_len] ||= 6
30
31
  rep=[]
31
32
  percents={}
@@ -9,14 +9,42 @@ require 'cgi'
9
9
  module Perf
10
10
  class ReportFormatHtml < ReportFormat
11
11
 
12
- PERCENT_FORMAT = "%.3f"
13
- INDENT = "&nbsp;"*3
12
+ PERCENT_FORMAT = "%.2f" # default for :time_format
13
+ TIME_FORMAT = "%.7f" # default for :percent_format
14
+ COUNT_FORMAT = "%d" # default for :count_format
15
+ INDENT = "&nbsp;"*3 # default for :indent_string
14
16
 
15
17
  def initialize
16
18
  super
17
19
  @line=0
18
20
  end
19
21
 
22
+ # Formats the report in HTML format and returns an array of strings containing the report.
23
+ #
24
+ # ==== Attributes
25
+ #
26
+ # * +perf+ - The Perf::Meter object to report
27
+ # * +options+ - A hash of options as follows:
28
+ # :time_format => sprintf format of the time (see TIME_FORMAT for default)
29
+ # :percent_foramt => sprintf format of the percent (see PERCENT_FORMAT for default)
30
+ # :count_format => sprintf format of the count (see COUNT_FORMAT for default)
31
+ # :indent_string => what string to use to indent the path (see INDENT for default)
32
+ #
33
+ # ==== Example
34
+ #
35
+ # m=Perf::Meter.new
36
+ # m.measure(:something) { something }
37
+ # m.report_html()
38
+
39
+ def format(perf,options={})
40
+ options||={}
41
+ @time_format = options[:time_format] || TIME_FORMAT
42
+ @percent_format = options[:percent_format] || PERCENT_FORMAT
43
+ @count_format = options[:count_format] || COUNT_FORMAT
44
+ @indent_string = options[:indent_string] || INDENT
45
+ super
46
+ end
47
+
20
48
  # Formats the header
21
49
  def format_header(v)
22
50
  "<table class='rubyperf_report'><tr>" \
@@ -33,15 +61,15 @@ module Perf
33
61
  # Formats the measure
34
62
  def format_measure(v)
35
63
  @line+=1
36
- percent= v[:percent].is_a?(String) ? v[:percent] : (PERCENT_FORMAT%v[:percent])
64
+ percent= v[:percent].is_a?(String) ? v[:percent] : (@percent_format % v[:percent])
37
65
  "<tr class='#{@line % 2==0 ? "even_row" : "odd_row"}'>" \
38
66
  "<td class='title'>#{v[:title]}</td>" \
39
67
  "<td class='percent'>#{percent}</td>" \
40
- "<td class='count'>#{v[:count]}</td>" \
41
- "<td class='user_time'>#{v[:time].utime}</td>" \
42
- "<td class='system_time'>#{v[:time].stime}</td>" \
43
- "<td class='total_time'>#{v[:time].total}</td>" \
44
- "<td class='real_time'>#{v[:time].real}</td>" \
68
+ "<td class='count'>#{@count_format % v[:count]}</td>" \
69
+ "<td class='user_time'>#{@time_format % v[:time].utime}</td>" \
70
+ "<td class='system_time'>#{@time_format % v[:time].stime}</td>" \
71
+ "<td class='total_time'>#{@time_format % v[:time].total}</td>" \
72
+ "<td class='real_time'>#{@time_format % v[:time].real}</td>" \
45
73
  "</tr>"
46
74
  end
47
75
 
@@ -51,7 +79,7 @@ module Perf
51
79
 
52
80
  def format_title(what,options)
53
81
  path=what.split("\\")
54
- "#{(path.size-2) ? INDENT*(path.size-2) : ""}\\#{CGI.escapeHTML(path.last)}"
82
+ "#{(path.size-2) ? @indent_string * (path.size-2) : ""}\\#{CGI.escapeHTML(path.last)}"
55
83
  end
56
84
 
57
85
  end
@@ -49,6 +49,7 @@ module Perf
49
49
  EXTRA_SPACES_AFTER_TITLE = 2
50
50
 
51
51
  def format(perf,options={})
52
+ options ||= {}
52
53
  options[:indent] ||= DEFAULT_INDENT
53
54
  super perf,options
54
55
  end
data/rubyperf.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubyperf}
8
- s.version = "1.3.1"
8
+ s.version = "1.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["lpasqualis"]
@@ -44,13 +44,14 @@ Gem::Specification.new do |s|
44
44
  s.homepage = %q{http://github.com/lpasqualis/rubyperf}
45
45
  s.licenses = ["MIT"]
46
46
  s.require_paths = ["lib"]
47
- s.rubygems_version = %q{1.4.2}
47
+ s.rubygems_version = %q{1.3.6}
48
48
  s.summary = %q{rubyperf helps you measure ruby code performance}
49
49
 
50
50
  if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
52
  s.specification_version = 3
52
53
 
53
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
55
  s.add_development_dependency(%q<shoulda>, [">= 0"])
55
56
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
56
57
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -108,6 +108,7 @@ class TestPerfMeter < Test::Unit::TestCase
108
108
  assert PerfTestExample.new.methods.sort == imethods
109
109
 
110
110
  assert_equal 6,m.report_simple.length
111
+ assert_equal 6,m.report_html(:percent_format=>"%.8f").length
111
112
  assert_equal 6,m.report_html.length
112
113
  assert_equal ['\methods,0',
113
114
  '\methods\#<Class:PerfTestExample>.static_method,1',
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyperf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 3
9
- - 1
10
- version: 1.3.1
8
+ - 2
9
+ segments_generated: true
10
+ version: 1.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - lpasqualis
@@ -20,64 +20,60 @@ default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
23
+ type: :development
24
+ name: shoulda
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
28
- hash: 3
29
29
  segments:
30
30
  - 0
31
+ segments_generated: true
31
32
  version: "0"
32
- type: :development
33
- name: shoulda
34
- version_requirements: *id001
33
+ requirement: *id001
35
34
  - !ruby/object:Gem::Dependency
36
35
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
36
+ type: :development
37
+ name: bundler
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ~>
41
41
  - !ruby/object:Gem::Version
42
- hash: 23
43
42
  segments:
44
43
  - 1
45
44
  - 0
46
45
  - 0
46
+ segments_generated: true
47
47
  version: 1.0.0
48
- type: :development
49
- name: bundler
50
- version_requirements: *id002
48
+ requirement: *id002
51
49
  - !ruby/object:Gem::Dependency
52
50
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
51
+ type: :development
52
+ name: jeweler
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
54
  requirements:
56
55
  - - ~>
57
56
  - !ruby/object:Gem::Version
58
- hash: 7
59
57
  segments:
60
58
  - 1
61
59
  - 6
62
60
  - 4
61
+ segments_generated: true
63
62
  version: 1.6.4
64
- type: :development
65
- name: jeweler
66
- version_requirements: *id003
63
+ requirement: *id003
67
64
  - !ruby/object:Gem::Dependency
68
65
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
66
+ type: :development
67
+ name: rcov
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
69
  requirements:
72
70
  - - ">="
73
71
  - !ruby/object:Gem::Version
74
- hash: 3
75
72
  segments:
76
73
  - 0
74
+ segments_generated: true
77
75
  version: "0"
78
- type: :development
79
- name: rcov
80
- version_requirements: *id004
76
+ requirement: *id004
81
77
  description: Used to easily measure the performance of blocks of Ruby code, expressions and methods; provides reporting in various formats
82
78
  email: lpasqualis@gmail.com
83
79
  executables: []
@@ -121,27 +117,25 @@ rdoc_options: []
121
117
  require_paths:
122
118
  - lib
123
119
  required_ruby_version: !ruby/object:Gem::Requirement
124
- none: false
125
120
  requirements:
126
121
  - - ">="
127
122
  - !ruby/object:Gem::Version
128
- hash: 3
129
123
  segments:
130
124
  - 0
125
+ segments_generated: true
131
126
  version: "0"
132
127
  required_rubygems_version: !ruby/object:Gem::Requirement
133
- none: false
134
128
  requirements:
135
129
  - - ">="
136
130
  - !ruby/object:Gem::Version
137
- hash: 3
138
131
  segments:
139
132
  - 0
133
+ segments_generated: true
140
134
  version: "0"
141
135
  requirements: []
142
136
 
143
137
  rubyforge_project:
144
- rubygems_version: 1.4.2
138
+ rubygems_version: 1.3.6
145
139
  signing_key:
146
140
  specification_version: 3
147
141
  summary: rubyperf helps you measure ruby code performance