rubyperf 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
data/lib/perf/meter.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require "benchmark"
7
+ require "rubyperf"
7
8
 
8
9
  module Perf
9
10
 
@@ -42,8 +43,10 @@ module Perf
42
43
  @instrumented_methods = {METHOD_TYPE_INSTANCE=>[],METHOD_TYPE_CLASS=>[]}
43
44
  @class_methods = []
44
45
  @subtract_overhead = @options[:subtract_overhead]
45
- @@overhead ||= measure_overhead if @subtract_overhead
46
- @measurements = {} # A hash of Measure
46
+ if @subtract_overhead
47
+ @@overhead ||= measure_overhead
48
+ @measurements = {} # A hash of Measure; must repeat here to cleanup what measure_overhead did
49
+ end
47
50
  end
48
51
 
49
52
  def overhead
@@ -54,6 +57,10 @@ module Perf
54
57
  end
55
58
  end
56
59
 
60
+ def has_measures?
61
+ @measurements.length > 0
62
+ end
63
+
57
64
  # Returns the total time - expressed with a Benchmark::Tms object - for all the blocks measures
58
65
  def blocks_time
59
66
  @measurements[PATH_MEASURES].time if @measurements[PATH_MEASURES]
@@ -3,6 +3,8 @@
3
3
  # https://github.com/lpasqualis/rubyperf
4
4
  #
5
5
 
6
+ require "rubyperf"
7
+
6
8
  module Perf
7
9
 
8
10
  # Very simple Perf::Meter factory and singleton management.
@@ -12,6 +12,16 @@ module Perf
12
12
  #
13
13
  class NoOpMeter
14
14
 
15
+ def measurements
16
+ end
17
+
18
+ def current_path
19
+ end
20
+
21
+ def has_measures?
22
+ false
23
+ end
24
+
15
25
  def initialize(options=nil)
16
26
  end
17
27
 
@@ -67,12 +77,16 @@ module Perf
67
77
 
68
78
  def method_missing(method_sym, *arguments, &block)
69
79
  if method_sym.to_s =~ /^report_(.*)$/
70
- klass=Object.const_get("Perf").const_get("ReportFormat#{$1.capitalize}")
80
+ klass=Object.const_get("Perf").const_get("ReportFormat#{camelize($1)}")
71
81
  return nil if klass
72
82
  end
73
83
  super
74
84
  end
75
85
 
86
+ def camelize(from)
87
+ from.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
88
+ end
89
+
76
90
  end
77
91
 
78
92
  end
@@ -3,6 +3,8 @@
3
3
  # https://github.com/lpasqualis/rubyperf
4
4
  #
5
5
 
6
+ require "rubyperf"
7
+
6
8
  module Perf
7
9
 
8
10
  #
@@ -5,7 +5,6 @@
5
5
 
6
6
 
7
7
  require 'rubyperf'
8
- require 'cgi'
9
8
 
10
9
  module Perf
11
10
 
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.2.0"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["lpasqualis"]
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "test/perf_test_example.rb",
39
39
  "test/rubyperf_test_helpers.rb",
40
40
  "test/test_meter_factory.rb",
41
+ "test/test_no_op_meter.rb",
41
42
  "test/test_perf_meter.rb"
42
43
  ]
43
44
  s.homepage = %q{http://github.com/lpasqualis/rubyperf}
@@ -0,0 +1,53 @@
1
+ #
2
+ # Copyright (c) 2012 Lorenzo Pasqualis - DreamBox Learning, Inc
3
+ # https://github.com/lpasqualis/rubyperf
4
+ #
5
+
6
+ require "test/unit"
7
+
8
+ require 'helper'
9
+
10
+ require 'rubyperf'
11
+
12
+ require 'rubyperf_test_helpers'
13
+ require 'perf_test_example'
14
+
15
+ class TestNoOpMeter < Test::Unit::TestCase
16
+
17
+ def test_basic
18
+ m=Perf::NoOpMeter.new
19
+ assert !m.has_measures?
20
+ v=m.measure(:a) do
21
+ m.measure(:b) do
22
+ 123
23
+ end
24
+ end
25
+ assert_equal 123,v
26
+
27
+ m.method_meters(PerfTestExample,[:test,:test_np,:test_with_measure],[:static_method]) do
28
+ a=PerfTestExample.new
29
+ a.test(1,2,3)
30
+ a.test_np
31
+ a.test_with_measure
32
+ PerfTestExample.static_method
33
+ end
34
+
35
+ assert_nil m.report_html
36
+ assert_nil m.report_simple
37
+ assert_nil m.report_list_of_measures
38
+ error=false
39
+ begin
40
+ m.report_this_does_not_exists
41
+ rescue
42
+ error=true
43
+ end
44
+ assert error
45
+ assert_nil m.measurements
46
+ assert_nil m.current_path
47
+
48
+ assert_equal 123,m.measure_result(:something) {123}
49
+ assert_equal 123,m.measure_result(:something) {m.measure(:blah){123}}
50
+ end
51
+
52
+
53
+ end
@@ -116,6 +116,13 @@ class TestPerfMeter < Test::Unit::TestCase
116
116
  m.report_list_of_measures
117
117
  end
118
118
 
119
+ def test_has_measures
120
+ m=Perf::Meter.new
121
+ assert !m.has_measures?
122
+ m.measure(:a) {assert m.has_measures?}
123
+ assert m.has_measures?
124
+ end
125
+
119
126
  def test_methods_with_measure
120
127
  Perf::MeterFactory.clear_all!
121
128
  m=Perf::MeterFactory.get
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: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 1.2.0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - lpasqualis
@@ -109,6 +109,7 @@ files:
109
109
  - test/perf_test_example.rb
110
110
  - test/rubyperf_test_helpers.rb
111
111
  - test/test_meter_factory.rb
112
+ - test/test_no_op_meter.rb
112
113
  - test/test_perf_meter.rb
113
114
  has_rdoc: true
114
115
  homepage: http://github.com/lpasqualis/rubyperf