benelux 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,12 @@
1
1
  BENELUX, CHANGES
2
2
 
3
+
4
+ #### 0.5.8 (2010-03-05) ###############################
5
+
6
+ * CHANGE: Added sum and sumsq to Benelux::Stats::Calculator#to_hash
7
+ * ADDED: Support for timer and counter aliases
8
+
9
+
3
10
  #### 0.5.7 (2010-02-20) ###############################
4
11
 
5
12
  * CHANGE: Remove hanna dependency
@@ -13,6 +20,7 @@ BENELUX, CHANGES
13
20
  * ADDED: Benelux.timeline_chunk, Benelux.timeline_updates
14
21
  * ADDED: Calculator#to_json
15
22
 
23
+
16
24
  #### 0.5.5 (2010-01-16) ###############################
17
25
 
18
26
  * ADDED: Benelux.bm
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "benelux"
3
3
  s.rubyforge_project = 'benelux'
4
- s.version = "0.5.7"
4
+ s.version = "0.5.8"
5
5
  s.summary = "Benelux: A mad way to time Ruby codes"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
@@ -4,7 +4,7 @@ require 'thwait'
4
4
  require 'selectable'
5
5
 
6
6
  module Benelux
7
- VERSION = "0.5.7"
7
+ VERSION = "0.5.8"
8
8
  NOTSUPPORTED = [Class, Object, Kernel]
9
9
 
10
10
  class BeneluxError < RuntimeError; end
@@ -147,15 +147,15 @@ module Benelux
147
147
  !Benelux.packed_method(klass, meth).nil?
148
148
  end
149
149
 
150
- def Benelux.add_timer klass, meth, &blk
150
+ def Benelux.add_timer klass, meth, aliaz=nil, &blk
151
151
  raise NotSupported, klass unless Benelux.supported? klass
152
152
  raise AlreadyTimed, klass if Benelux.packed_method? klass, meth
153
- Benelux::MethodTimer.new klass, meth, &blk
153
+ Benelux::MethodTimer.new klass, meth, aliaz, &blk
154
154
  end
155
155
 
156
- def Benelux.add_counter klass, meth, &blk
156
+ def Benelux.add_counter klass, meth, aliaz=nil, &blk
157
157
  raise NotSupported, klass unless Benelux.supported? klass
158
- Benelux::MethodCounter.new klass, meth, &blk
158
+ Benelux::MethodCounter.new klass, meth, aliaz, &blk
159
159
  end
160
160
 
161
161
  def Benelux.ld(*msg)
@@ -4,6 +4,7 @@ module Benelux
4
4
  class MethodPacker
5
5
  include Selectable::Object
6
6
 
7
+ attr_accessor :methorig
7
8
  attr_accessor :aliaz
8
9
  attr_reader :klass
9
10
  attr_reader :meth
@@ -11,7 +12,8 @@ module Benelux
11
12
 
12
13
  # * +k+ is a class
13
14
  # * +m+ is the name of an instance method in +k+
14
- #
15
+ # * +aliaz+ is an optional name for
16
+ #
15
17
  # This method makes the following changes to class +k+.
16
18
  #
17
19
  # * Add a timeline attic to and include +Benelux+
@@ -19,12 +21,13 @@ module Benelux
19
21
  # __benelux_execute_2151884308_2165479316
20
22
  # * Install a new method with the name +m+.
21
23
  #
22
- def initialize(k,m,&blk)
24
+ def initialize(k,m,aliaz,&blk)
23
25
  Benelux.ld "%20s: %s#%s" % [self.class, k, m]
24
26
  if Benelux.packed_method? k, m
25
27
  raise SelectableError, "Already defined (#{k} #{m})"
26
28
  end
27
- @klass, @meth, @blk = k, m, blk
29
+ @klass, @meth, @aliaz, @blk = k, m, aliaz, blk
30
+ @aliaz ||= meth
28
31
  @klass.extend Attic unless @klass.kind_of?(Attic)
29
32
  unless @klass.kind_of?(Benelux)
30
33
  @klass.attic :timeline
@@ -36,10 +39,10 @@ module Benelux
36
39
  ## raise NoMethodError, "undefined method `#{meth}' for #{obj}:Class"
37
40
  ##end
38
41
  thread_id, call_id = Thread.current.object_id.abs, @klass.object_id.abs
39
- @aliaz = a = :"__benelux_#{@meth}_#{thread_id}_#{call_id}"
40
- Benelux.ld "%20s: %s" % ['Alias', @aliaz]
42
+ @methorig = methorig = :"__benelux_#{@meth}_#{thread_id}_#{call_id}"
43
+ Benelux.ld "%20s: %s" % ['Alias', @methorig]
41
44
  @klass.module_eval do
42
- alias_method a, m # Can't use the instance variables
45
+ alias_method methorig, m # Can't use the instance variables
43
46
  end
44
47
  install_method # see generate_packed_method
45
48
  self.add_tags :class => @klass.to_s.to_sym,
@@ -85,7 +88,7 @@ module Benelux
85
88
  end
86
89
 
87
90
  # Creates a method definition (for an eval). The
88
- # method is named +@meth+ and it calls +@aliaz+.
91
+ # method is named +@meth+ and it calls +@methorig+.
89
92
  #
90
93
  # The new method adds a Mark to the thread timeline
91
94
  # before and after +@alias+ is called. It also adds
@@ -95,16 +98,16 @@ module Benelux
95
98
  def #{@meth}(*args, &block)
96
99
  call_id = "" << self.object_id.abs.to_s << args.object_id.abs.to_s
97
100
  Benelux.current_track :global unless Benelux.known_thread?
98
- mark_a = Benelux.thread_timeline.add_mark :'#{@meth}_a'
101
+ mark_a = Benelux.thread_timeline.add_mark :'#{@aliaz}_a'
99
102
  mark_a.add_tag :call_id => call_id
100
103
  tags = mark_a.tags
101
- ret = #{@aliaz}(*args, &block)
104
+ ret = #{@methorig}(*args, &block)
102
105
  rescue => ex # We do this so we can use
103
106
  raise ex # ex in the ensure block.
104
107
  ensure
105
- mark_z = Benelux.thread_timeline.add_mark :'#{@meth}_z'
108
+ mark_z = Benelux.thread_timeline.add_mark :'#{@aliaz}_z'
106
109
  mark_z.tags = tags # In case tags were added between these marks
107
- range = Benelux.thread_timeline.add_range :'#{@meth}', mark_a, mark_z
110
+ range = Benelux.thread_timeline.add_range :'#{@aliaz}', mark_a, mark_z
108
111
  range.exception = ex if defined?(ex) && !ex.nil?
109
112
  end
110
113
  }
@@ -123,7 +126,7 @@ module Benelux
123
126
  Benelux.current_track :global unless Benelux.known_thread?
124
127
  # Get a reference to this MethodCounter instance
125
128
  cmd = Benelux.packed_method #{@klass}, :#{@meth}
126
- ret = #{@aliaz}(*args, &block)
129
+ ret = #{@methorig}(*args, &block)
127
130
  count = cmd.determine_count(args, ret)
128
131
  #Benelux.ld "COUNT(:#{@meth}): \#{count}"
129
132
  Benelux.thread_timeline.add_count :'#{@meth}', count
@@ -157,7 +157,6 @@ module Benelux
157
157
  @sum += other.sum
158
158
  @sumsq += other.sumsq
159
159
  @n += other.n
160
-
161
160
  self
162
161
  end
163
162
 
@@ -210,14 +209,14 @@ module Benelux
210
209
  return 0.0 if @n <= 1
211
210
  # (sqrt( ((s).sumsq - ( (s).sum * (s).sum / (s).n)) / ((s).n-1) ))
212
211
  begin
213
- return Math.sqrt( (@sumsq - ( @sum * @sum / @n)) / (@n-1) )
212
+ return Math.sqrt( (@sumsq - (@sum * @sum / @n)) / (@n-1) )
214
213
  rescue Errno::EDOM
215
214
  return 0.0
216
215
  end
217
216
  end
218
217
 
219
218
  def to_hash
220
- { :min => min, :mean => mean, :max => max, :sd => sd, :n => n }
219
+ { :min => min, :mean => mean, :max => max, :sd => sd, :n => n, :sum => @sum, :sumsq => @sumsq }
221
220
  end
222
221
 
223
222
  def to_json
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benelux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-20 00:00:00 -05:00
12
+ date: 2010-03-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15