benelux 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGES.txt +4 -1
  2. data/README.rdoc +20 -5
  3. data/benelux.gemspec +2 -2
  4. data/lib/benelux.rb +61 -2
  5. metadata +5 -5
data/CHANGES.txt CHANGED
@@ -1,10 +1,13 @@
1
1
  BENELUX, CHANGES
2
2
 
3
+ #### 0.5.5 (2010-01-16) ###############################
4
+
5
+ * ADDED: Benelux.bm
6
+
3
7
  #### 0.5.4 (2010-01-13) ###############################
4
8
 
5
9
  * CHANGE: Timeline#add_message now supports objects of any type (not just Strings)
6
10
 
7
-
8
11
  #### 0.5.3 (2009-11-16) ###############################
9
12
 
10
13
  * FIXED: Process dead threads only once
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Benelux v0.5
2
2
 
3
- <b>A mad timeline for your Ruby codes</b>
3
+ <b>A mad way to time Ruby codes</b>
4
4
 
5
5
 
6
6
  == Features
@@ -10,14 +10,30 @@
10
10
  * Granular statistics
11
11
  * Thread-safe
12
12
 
13
-
13
+ == Example
14
+
15
+ require 'benelux'
16
+
17
+ # Similar to Benchmark::Tms with the addition of
18
+ # standard deviation, mean value, and total, for
19
+ # each of the times.
20
+ tms = Benelux.bm(1000000, 5) do
21
+ rand
22
+ end
23
+
24
+ tms.samples # => 5
25
+ tms.real # => 0.45
26
+ tms.real.sd # => 0.04
27
+ tms.utime # => 0.44
28
+ tms.utime.sd # => 0.02
29
+
14
30
  == Installation
15
31
 
16
32
  Get it in one of the following ways:
17
33
 
18
- $ gem install benelux
34
+ $ gem install benelux --source http://gemcutter.org
35
+ $ sudo gem install benelux --source http://gemcutter.org
19
36
  $ git clone git://github.com/delano/benelux.git
20
- $ gem install delano-benelux --source http://gems.github.com
21
37
 
22
38
 
23
39
  == More Information
@@ -25,7 +41,6 @@ Get it in one of the following ways:
25
41
  * Codes[http://github.com/delano/benelux]
26
42
  * RDocs[http://delano.github.com/benelux]
27
43
 
28
-
29
44
  == Credits
30
45
 
31
46
  * Delano Mandelbaum (http://solutious.com)
data/benelux.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "benelux"
3
3
  s.rubyforge_project = 'benelux'
4
- s.version = "0.5.4"
5
- s.summary = "Benelux: A mad timeline for Ruby codes"
4
+ s.version = "0.5.5"
5
+ s.summary = "Benelux: A mad way to time Ruby codes"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
8
8
  s.email = "delano@solutious.com"
data/lib/benelux.rb CHANGED
@@ -5,7 +5,7 @@ require 'thwait'
5
5
  require 'selectable'
6
6
 
7
7
  module Benelux
8
- VERSION = "0.5.4"
8
+ VERSION = "0.5.5"
9
9
  NOTSUPPORTED = [Class, Object, Kernel]
10
10
 
11
11
  class BeneluxError < RuntimeError; end
@@ -161,7 +161,66 @@ module Benelux
161
161
  def Benelux.disable_debug; @@debug = false; end
162
162
  def Benelux.debug?; @@debug; end
163
163
 
164
-
164
+ # Similar to Benchmark::Tms with the addition of
165
+ # standard deviation, mean, and total, for each of
166
+ # the data times.
167
+ #
168
+ # tms = Benelux::Tms.new
169
+ # tms.real.sd # standard deviation
170
+ # tms.utime.mean # mean value
171
+ # tms.total.n # number of data points
172
+ #
173
+ # See Benelux::Stats::Calculator
174
+ #
175
+ class Tms < Struct.new :label, :real, :cstime, :cutime, :stime, :utime, :total
176
+ attr_reader :samples
177
+ # +tms+ is a Benchmark::Tms object
178
+ def initialize tms=nil
179
+ @samples = 0
180
+ members.each_with_index { |n, index|
181
+ next if n.to_s == 'label'
182
+ self.send("#{n}=", Stats::Calculator.new)
183
+ }
184
+ sample tms unless tms.nil?
185
+ end
186
+ def sample(tms)
187
+ @samples += 1
188
+ self.label ||= tms.label
189
+ members.each_with_index { |n, index|
190
+ next if n.to_s == 'label'
191
+ self.send(n).sample tms.send(n) || 0
192
+ }
193
+ end
194
+ def to_s
195
+ total.mean
196
+ end
197
+ def inspect
198
+ fields = members.collect { |f|
199
+ next unless Stats::Calculator === self.send(f)
200
+ '%s=%.2f@%.2f' % [f, self.send(f).mean, self.send(f).sd]
201
+ }.compact
202
+ args = [self.class.to_s, self.hexoid, samples, fields.join(' ')]
203
+ '#<%s:%s samples=%d %s>' % args
204
+ end
205
+ end
206
+
207
+ # Run a benchmark the healthy way: with a warmup run, with
208
+ # multiple repetitions, and standard deviation.
209
+ #
210
+ # * +n+ Number of times to execute +blk+ (one data sample)
211
+ # * +reps+ Number of data samples to collect
212
+ # * +blk+ a Ruby block to benchmark
213
+ #
214
+ # Returns a Benelux::Tms object
215
+ def Benelux.bm(n=1, reps=5, &blk)
216
+ require 'benchmark'
217
+ n.times &blk
218
+ tms = Benelux::Tms.new
219
+ reps.times do |rep|
220
+ tms.sample Benchmark.measure() {n.times &blk}
221
+ end
222
+ tms
223
+ end
165
224
  end
166
225
 
167
226
 
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.4
4
+ version: 0.5.5
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-01-13 00:00:00 -05:00
12
+ date: 2010-01-16 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- description: "Benelux: A mad timeline for Ruby codes"
25
+ description: "Benelux: A mad way to time Ruby codes"
26
26
  email: delano@solutious.com
27
27
  executables: []
28
28
 
@@ -68,7 +68,7 @@ post_install_message:
68
68
  rdoc_options:
69
69
  - --line-numbers
70
70
  - --title
71
- - "Benelux: A mad timeline for Ruby codes"
71
+ - "Benelux: A mad way to time Ruby codes"
72
72
  - --main
73
73
  - README.rdoc
74
74
  require_paths:
@@ -91,6 +91,6 @@ rubyforge_project: benelux
91
91
  rubygems_version: 1.3.5
92
92
  signing_key:
93
93
  specification_version: 3
94
- summary: "Benelux: A mad timeline for Ruby codes"
94
+ summary: "Benelux: A mad way to time Ruby codes"
95
95
  test_files: []
96
96