tach 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +13 -0
  2. data/lib/tach.rb +4 -27
  3. data/tach.gemspec +2 -2
  4. metadata +3 -3
@@ -23,6 +23,19 @@ Each tach should have a name, so you can recognize them in the results
23
23
  Then inside the tach block you should specify the code you care about comparing.
24
24
  The name of each tach will be displayed as it starts
25
25
 
26
+ For things requiring more complex setup you can make them do their own iteration, for instance:
27
+
28
+ Tach.meter(4) do
29
+
30
+ tach('complex') do |count|
31
+ duration = rand
32
+ count.times do
33
+ sleep(duration)
34
+ end
35
+ end
36
+
37
+ end
38
+
26
39
  == Copyright
27
40
 
28
41
  (The MIT License)
@@ -3,8 +3,10 @@ require 'formatador'
3
3
 
4
4
  module Tach
5
5
 
6
+ STDOUT.sync = true
7
+
6
8
  unless const_defined?(:VERSION)
7
- VERSION = '0.0.7'
9
+ VERSION = '0.0.8'
8
10
  end
9
11
 
10
12
  def self.meter(times = 1, &block)
@@ -37,11 +39,9 @@ module Tach
37
39
  data << { :tach => name, :total => format("%8.6f", run_tach(name, @times, &block)) }
38
40
  unless [name, block] == @benchmarks.last
39
41
  print(', ')
40
- STDOUT.flush
41
42
  end
42
43
  end
43
44
  print("]\n\n")
44
- STDOUT.flush
45
45
  data.sort! {|x,y| x[:total].to_f <=> y[:total].to_f }
46
46
  Formatador.display_table(data, [:tach, :total])
47
47
  Formatador.display_line
@@ -56,10 +56,9 @@ module Tach
56
56
  def run_tach(name, count, &benchmark)
57
57
  GC::start
58
58
  print(name)
59
- STDOUT.flush
60
59
  tach_start = Time.now
61
60
 
62
- if benchmark.arity == 0
61
+ if benchmark.arity <= 0
63
62
  count.times { benchmark.call }
64
63
  else
65
64
  benchmark.call(count)
@@ -106,26 +105,4 @@ if __FILE__ == $0
106
105
  end
107
106
  end
108
107
 
109
- require 'benchmark'
110
- Benchmark.bm do |bench|
111
- bench.report('regex 1') do
112
- 100_000.times do
113
- header = data.match(/(.*):\s(.*)/)
114
- [$1, $2]
115
- end
116
- end
117
- bench.report('regex 2') do
118
- 100_000.times do
119
- header = data.match(/(.*):\s(.*)/)
120
- [$1, $2]
121
- end
122
- end
123
- bench.report('regex 3') do
124
- 100_000.times do
125
- header = data.match(/(.*):\s(.*)/)
126
- [$1, $2]
127
- end
128
- end
129
- end
130
-
131
108
  end
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'tach'
16
- s.version = '0.0.7'
17
- s.date = '2010-12-07'
16
+ s.version = '0.0.8'
17
+ s.date = '2010-12-08'
18
18
  s.rubyforge_project = 'tach'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - geemus (Wesley Beary)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-07 00:00:00 -08:00
17
+ date: 2010-12-08 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency