benelux 0.5.17 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,8 +1,9 @@
1
1
  BENELUX, CHANGES
2
2
 
3
- #### 0.5.17 (2011-02-26) ##############################
4
3
 
5
- * FIXED: Fix for bug in Ruby 1.9.2 (same fix as in 0.6.1)
4
+ #### 0.6.0 (2010-09-05) ##############################
5
+
6
+ * CHANGE: Thread now belongs to Track (previously reversed)
6
7
 
7
8
  #### 0.5.16 (2010-06-08) ##############################
8
9
 
data/benelux.gemspec CHANGED
@@ -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.17"
4
+ s.version = "0.6.0"
5
5
  s.summary = "Benelux: A mad way to time Ruby codes"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
@@ -13,7 +13,7 @@
13
13
  s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
14
14
  s.require_paths = %w[lib]
15
15
 
16
- s.add_dependency("storable", [">= 0.6.5"])
16
+ s.add_dependency("storable", [">= 0.8.0"])
17
17
 
18
18
  # = MANIFEST =
19
19
  # git ls-files
@@ -35,16 +35,6 @@
35
35
  lib/selectable/global.rb
36
36
  lib/selectable/object.rb
37
37
  lib/selectable/tags.rb
38
- tryouts/10_stats_tryouts.rb
39
- tryouts/11_selectable_tryouts.rb
40
- tryouts/20_tracks_tryouts.rb
41
- tryouts/30_reporter_tryouts.rb
42
- tryouts/30_timeline_tryouts.rb
43
- tryouts/benelux_bm.rb
44
- tryouts/proofs/alias_performance.rb
45
- tryouts/proofs/array_performance.rb
46
- tryouts/proofs/thread_array.rb
47
- tryouts/proofs/timer_threading.rb
48
38
  )
49
39
 
50
40
 
data/lib/benelux.rb CHANGED
@@ -5,7 +5,7 @@ require 'selectable'
5
5
  require 'storable'
6
6
 
7
7
  module Benelux
8
- VERSION = "0.5.17"
8
+ VERSION = "0.6.0"
9
9
  NOTSUPPORTED = [Class, Object, Kernel]
10
10
 
11
11
  class BeneluxError < RuntimeError; end
@@ -66,15 +66,13 @@ module Benelux
66
66
  # If +track+ is nil, it returns the Track object for the
67
67
  # Track associated to the current thread.
68
68
  #
69
- def Benelux.current_track(name=nil,group=nil)
69
+ def Benelux.current_track(name=nil,timeline=nil)
70
70
  if name.nil?
71
71
  name = Thread.current.track_name
72
72
  else
73
73
  Thread.current.track_name = name
74
74
  @@mutex.synchronize do
75
- Thread.current.timeline ||= Benelux::Timeline.new
76
- Thread.current.rotated_timelines ||= []
77
- @tracks[name] ||= Track.new(name, group)
75
+ @tracks[name] ||= Track.new(name, timeline || Thread.current.timeline || Benelux::Timeline.new)
78
76
  @tracks[name].add_thread Thread.current
79
77
  @known_threads << Thread.current
80
78
  end
@@ -83,6 +81,14 @@ module Benelux
83
81
  end
84
82
  Benelux.current_track :main
85
83
 
84
+ def Benelux.merge_tracks
85
+ tl = Benelux::Timeline.new
86
+ tracks.each_pair do |trackid,track|
87
+ tl.merge! track.timeline
88
+ end
89
+ tl
90
+ end
91
+
86
92
  # Only updates data from threads that
87
93
  # are dead and rotated timelines.
88
94
  def Benelux.update_global_timeline
@@ -115,18 +121,6 @@ module Benelux
115
121
  end
116
122
  end
117
123
 
118
- # Thread tags become the default for any new Mark or Range.
119
- def Benelux.add_thread_tags(args=Selectable::Tags.new)
120
- Benelux.thread_timeline.add_default_tags args
121
- end
122
- def Benelux.add_thread_tag(*args) add_thread_tags *args end
123
-
124
- def Benelux.remove_thread_tags(*args)
125
- Benelux.thread_timeline.remove_default_tags *args
126
- end
127
- def Benelux.remove_thread_tag(*args) remove_thread_tags *args end
128
-
129
-
130
124
  def Benelux.inspect
131
125
  str = ["Benelux"]
132
126
  str << "tracks:" << Benelux.tracks.inspect
@@ -23,9 +23,9 @@ end
23
23
 
24
24
  class Thread
25
25
  extend Attic
26
- attr_accessor :timeline
27
- attr_accessor :track_name
28
- attr_accessor :rotated_timelines
26
+ attic :timeline
27
+ attic :track_name
28
+ attic :rotated_timelines
29
29
  def rotate_timeline
30
30
  self.rotated_timelines << self.timeline
31
31
  tags = self.timeline.default_tags.clone
@@ -116,18 +116,21 @@ module Benelux
116
116
  def generate_packed_method
117
117
  %Q{
118
118
  def #{@meth}(*args, &block)
119
+ #p ["#{@meth} 1"]
119
120
  call_id = "" << self.object_id.abs.to_s << args.object_id.abs.to_s
120
121
  Benelux.current_track :global unless Benelux.known_thread?
121
- mark_a = Benelux.thread_timeline.add_mark :'#{@aliaz}_a'
122
+ mark_a = Benelux.current_track.timeline.add_mark :'#{@aliaz}_a'
122
123
  mark_a.add_tag :call_id => call_id
123
124
  tags = mark_a.tags
124
125
  ret = #{@methorig}(*args, &block)
126
+ #p ["#{@meth} 2"]
127
+ ret
125
128
  rescue => ex # We do this so we can use
126
129
  raise ex # ex in the ensure block.
127
130
  ensure
128
- mark_z = Benelux.thread_timeline.add_mark :'#{@aliaz}_z'
131
+ mark_z = Benelux.current_track.timeline.add_mark :'#{@aliaz}_z'
129
132
  mark_z.tags = tags # In case tags were added between these marks
130
- range = Benelux.thread_timeline.add_range :'#{@aliaz}', mark_a, mark_z
133
+ range = Benelux.current_track.timeline.add_range :'#{@aliaz}', mark_a, mark_z
131
134
  range.exception = ex if defined?(ex) && !ex.nil?
132
135
  end
133
136
  }
@@ -149,7 +152,7 @@ module Benelux
149
152
  ret = #{@methorig}(*args, &block)
150
153
  count = cmd.determine_count(args, ret)
151
154
  #Benelux.ld "COUNT(:#{@meth}): \#{count}"
152
- Benelux.thread_timeline.add_count :'#{@meth}', count
155
+ Benelux.current_track.timeline.add_count :'#{@meth}', count
153
156
  ret
154
157
  end
155
158
  }
data/lib/benelux/stats.rb CHANGED
@@ -151,11 +151,11 @@ module Benelux
151
151
  @min, @max = 0.0, 0.0
152
152
  end
153
153
 
154
- def samples(*args)
154
+ def samples(*args)
155
155
  args.flatten.each { |s| sample(s) }
156
156
  end
157
157
 
158
- def merge!(other)
158
+ def merge!(other)
159
159
  return self if other.n == 0
160
160
  if @n == 0
161
161
  @min, @max = other.min, other.max
data/lib/benelux/track.rb CHANGED
@@ -5,9 +5,11 @@ module Benelux
5
5
  attr_reader :name
6
6
  attr_reader :thread_group
7
7
  attr_reader :timeline
8
- def initialize(n,g=nil)
9
- @name, @thgrp = n, (g || ThreadGroup.new)
10
- @timeline = Benelux::Timeline.new
8
+ attr_reader :rotated_timelines
9
+ def initialize(n,t)
10
+ @name, @thgrp = n, ThreadGroup.new
11
+ @timeline = t || Benelux::Timeline.new
12
+ @rotated_timelines = []
11
13
  end
12
14
  def add_thread(t=Thread.current)
13
15
  @thgrp.add t
@@ -16,5 +18,18 @@ module Benelux
16
18
  def threads
17
19
  @thgrp.list
18
20
  end
21
+ def add_tags(args=Selectable::Tags.new)
22
+ timeline.add_default_tags args
23
+ end
24
+ def remove_tags(*args)
25
+ timeline.remove_default_tags *args
26
+ end
27
+ ##def rotate_timeline
28
+ ## self.rotated_timelines << self.timeline
29
+ ## tags = self.timeline.default_tags.clone
30
+ ## self.timeline = Benelux::Timeline.new
31
+ ## self.timeline.default_tags = tags
32
+ ## self.timeline
33
+ ##end
19
34
  end
20
35
  end
data/lib/selectable.rb CHANGED
@@ -87,4 +87,8 @@ end
87
87
 
88
88
  class TaggableString < String
89
89
  include Selectable::Object
90
+ def initialize(str, tags={})
91
+ super(str)
92
+ add_tags tags unless tags.empty?
93
+ end
90
94
  end
@@ -78,7 +78,7 @@ module Selectable
78
78
  end
79
79
 
80
80
  def method_missing(meth, *args)
81
- raise SelectableError, "#{meth}: #{args.first} is not a Hash or Array"
81
+ raise SelectableError, "#{meth}: #{args.first} is not a Hash or Array #{self}"
82
82
  end
83
83
 
84
84
  ## NOTE: This is helpful but defensive. Ponder!
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benelux
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.5.17
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
6
11
  platform: ruby
7
12
  authors:
8
13
  - Delano Mandelbaum
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-02-26 00:00:00 -05:00
18
+ date: 2010-09-05 00:00:00 -04:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -21,7 +26,12 @@ dependencies:
21
26
  requirements:
22
27
  - - ">="
23
28
  - !ruby/object:Gem::Version
24
- version: 0.6.5
29
+ hash: 63
30
+ segments:
31
+ - 0
32
+ - 8
33
+ - 0
34
+ version: 0.8.0
25
35
  type: :runtime
26
36
  version_requirements: *id001
27
37
  description: "Benelux: A mad way to time Ruby codes"
@@ -52,16 +62,6 @@ files:
52
62
  - lib/selectable/global.rb
53
63
  - lib/selectable/object.rb
54
64
  - lib/selectable/tags.rb
55
- - tryouts/10_stats_tryouts.rb
56
- - tryouts/11_selectable_tryouts.rb
57
- - tryouts/20_tracks_tryouts.rb
58
- - tryouts/30_reporter_tryouts.rb
59
- - tryouts/30_timeline_tryouts.rb
60
- - tryouts/benelux_bm.rb
61
- - tryouts/proofs/alias_performance.rb
62
- - tryouts/proofs/array_performance.rb
63
- - tryouts/proofs/thread_array.rb
64
- - tryouts/proofs/timer_threading.rb
65
65
  has_rdoc: true
66
66
  homepage: http://github.com/delano/benelux
67
67
  licenses: []
@@ -80,17 +80,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
83
86
  version: "0"
84
87
  required_rubygems_version: !ruby/object:Gem::Requirement
85
88
  none: false
86
89
  requirements:
87
90
  - - ">="
88
91
  - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
89
95
  version: "0"
90
96
  requirements: []
91
97
 
92
98
  rubyforge_project: benelux
93
- rubygems_version: 1.5.2
99
+ rubygems_version: 1.3.7
94
100
  signing_key:
95
101
  specification_version: 3
96
102
  summary: "Benelux: A mad way to time Ruby codes"
@@ -1,66 +0,0 @@
1
-
2
- group "Benelux"
3
-
4
- library :benelux, 'lib'
5
- tryouts "Calculator" do
6
- set :base, Benelux::Stats::Calculator.new
7
- dream :class, Benelux::Stats::Calculator
8
- dream :n, 10
9
- dream :sum, 45
10
- dream :sumsq, 285
11
- dream :min, 0
12
- dream :max, 9
13
- dream :proc, lambda { |calc| calc.sd.to_i == 3 }
14
- drill "can keep stats" do
15
- 10.times { |i| base.sample(i) }
16
- base
17
- end
18
-
19
- dream true
20
- drill "can add stats" do
21
- by_sample = Benelux::Stats::Calculator.new
22
- 10.times { |i| by_sample.sample(i) }
23
- by_sample += base
24
- by_merge = Benelux::Stats::Calculator.new
25
- by_merge.merge! base
26
- by_merge.merge! base
27
- stash :sample, by_sample
28
- stash :merge, by_merge
29
- by_sample == by_merge
30
- end
31
-
32
- end
33
-
34
- tryouts "Stats" do
35
- set :stat_names, [:execute, :request, :first_byte]
36
-
37
- dream stat_names
38
- drill "knows stats names" do
39
- stats = Benelux::Stats.new(stat_names)
40
- stats.names
41
- end
42
-
43
- drill "can keep multiple stats", true do
44
- stats = Benelux::Stats.new(stat_names)
45
- stats.execute.sample(rand)
46
- stats.request.sample(rand*-1)
47
- stats.execute != stats.request
48
- end
49
-
50
- dream [true, true, true]
51
- drill "can keep stats with tags" do
52
- stats = Benelux::Stats.new(stat_names)
53
- 3.times { |i|
54
- stats.execute.sample(rand, :usecase => '11')
55
- stats.execute.sample(rand, :usecase => '11', :request => '22')
56
- stats.execute.sample(rand, :request => '22')
57
- }
58
- stash :execute_stats, stats.execute
59
- [
60
- stats.execute['11'] == stats.execute[:usecase => '11'],
61
- stats.execute['22'] == stats.execute[:request => '22'],
62
- stats.execute['22','11'] == stats.execute[:usecase => '11', :request => '22']
63
- ]
64
- end
65
-
66
- end
@@ -1,92 +0,0 @@
1
-
2
- group "Benelux"
3
-
4
- library :benelux, 'lib'
5
- tryouts "Selectable" do
6
- set :base, SelectableArray.new
7
-
8
- setup do
9
- class ::TaggedItems
10
- include Selectable::Object
11
- end
12
- 10.times { |i|
13
- obj = TaggedItems.new
14
- obj.add_tags :index => i, :even => (i%2 == 0)
15
- base << obj
16
- }
17
- end
18
-
19
- dream :class, SelectableArray
20
- dream :size, 5
21
- drill "filter returns a new instance of the same object" do
22
- base.filter(:even => true)
23
- end
24
-
25
- dream :class, SelectableArray
26
- dream :object_id, base.object_id
27
- dream :size, 5
28
- drill "filter! makes permanent changes to itself" do
29
- base.filter! :even => true
30
- end
31
-
32
- end
33
-
34
-
35
- tryouts "Tags" do
36
- set :base, Selectable::Tags[:a => 1, :b => 2]
37
-
38
- drill "Can equal a Hash with the same keys/values", true do
39
- base == {:a => 1, :b => 2}
40
- end
41
-
42
- drill "Implements a comparison operator", true do
43
- base.respond_to? :'<=>'
44
- end
45
-
46
- drill "Comparison operator returns 0 for same values", 0 do
47
- base <=> {:a => 1, :b => 2}
48
- end
49
-
50
- drill "Comparison operator returns 1 when it's a superset of other", 1 do
51
- base <=> {:a => 1}
52
- end
53
-
54
- drill "Comparison operator returns -1 when it's a subset of other", -1 do
55
- base <=> {:a => 1, :b => 2, :c => 3}
56
- end
57
-
58
- drill "> returns false when compared to a hash with more key value pairs", false do
59
- base > {:a => 1, :b => 2, :c => 3}
60
- end
61
-
62
- drill "> returns true when compared to a hash with fewer key value pairs", true do
63
- base > {:b => 2}
64
- end
65
-
66
- drill "< returns true when compared to a hash with more key value pairs", true do
67
- base < {:a => 1, :b => 2, :c => 3}
68
- end
69
-
70
- drill "< returns false when compared to a hash with fewer key value pairs", false do
71
- base < {:b => 2}
72
- end
73
-
74
- drill "< returns false when compared to a hash with same values", false do
75
- base < {:a => 1, :b => 2}
76
- end
77
-
78
- drill "<= returns true when compared to a hash with same values", true do
79
- base <= {:b => 2, :a => 1}
80
- end
81
-
82
- drill "< returns false when compared to an array with same values", false do
83
- base < [1, 2]
84
- end
85
-
86
- drill "<= returns true when compared to an array with same values", true do
87
- base <= [2, 1]
88
- end
89
-
90
- end
91
-
92
-
@@ -1,22 +0,0 @@
1
- group "Benelux"
2
-
3
- library :benelux, 'lib'
4
- tryouts "Tracks" do
5
-
6
- dream [:track1, :track1]
7
- drill "Can specify current track" do
8
- Benelux.current_track :track1
9
- [Thread.current.track_name, Benelux.current_track.name]
10
- end
11
-
12
- dream :class, Benelux::Timeline
13
- drill "Track has a timeline" do
14
- Benelux.current_track.timeline
15
- end
16
-
17
- dream :exception, Benelux::UnknownTrack
18
- drill "raises exception when unknown track specified" do
19
- Benelux.track :name
20
- end
21
-
22
- end
@@ -1,34 +0,0 @@
1
- group "Benelux"
2
-
3
- library :benelux, 'lib'
4
- xtryouts "Reporter" do
5
- set :reporter, Benelux::Reporter.new
6
-
7
- drill "1", true do
8
- p Benelux
9
- end
10
-
11
- dream :exception, Benelux::BadRecursion
12
- xdrill "will not report on itself" do
13
- reporter.add_threads Thread.current
14
- end
15
-
16
- dream :class, ThreadsWait
17
- dream :empty?, false
18
- xdrill "can add threads" do
19
- 2.times {
20
- t = Thread.new do
21
- 3.times { sleep 1; }
22
- end
23
- reporter.add_thread t
24
- }
25
- reporter.thwait
26
- end
27
-
28
- dream true
29
- xdrill "will wait for known threads" do
30
- reporter.start
31
- reporter
32
- end
33
-
34
- end
@@ -1,60 +0,0 @@
1
-
2
-
3
- __END__
4
- # OLD (0.3):
5
-
6
- group "Benelux"
7
-
8
- library :benelux, 'lib'
9
- tryouts "Timelines" do
10
- set :tl, Benelux::Timeline.new
11
-
12
- setup do
13
- class ::Sleeper
14
- def do_something() sleep rand/3 end
15
- def another_method(t) t*2 end
16
- end
17
- end
18
-
19
- drill "Can set thread track", :track1 do
20
- Benelux.current_track :track1
21
- # Thread.current.track
22
- end
23
-
24
- drill "Add timers to existing objects", true do
25
- Benelux.add_timer Sleeper, :do_something
26
- Sleeper.new.respond_to? :timeline
27
- end
28
-
29
- dream :class, Benelux::Timeline
30
- dream :size, 3
31
- drill "create timeline with marks" do
32
- tl.add_default_tags :a => :frog
33
- tl.add_mark(:one)
34
- tl.add_default_tags :b => :rest
35
- tl.add_mark(:two)
36
- tl.add_default_tags :c => :tilt
37
- tl.add_mark(:three)
38
- tl.marks
39
- end
40
-
41
- dream :size, 2
42
- drill "select marks based on tags" do
43
- tl[:frog][:b => :rest]
44
- end
45
-
46
- dream :class, Benelux::Timeline
47
- dream :size, 10 # 5 * 2 = 10
48
- drill "Creates a timeline for the thread" do
49
- sleeper = Sleeper.new
50
- 5.times { sleeper.do_something }
51
- Benelux.thread_timeline
52
- end
53
-
54
- dream :class, Benelux::Timeline
55
- dream :size, 10
56
- drill "Creates a global timeline" do
57
- Benelux.update_all_track_timelines
58
- Benelux.timeline
59
- end
60
- end
@@ -1,9 +0,0 @@
1
- # $ ruby -Ilib tryouts/benelux_bm.rb
2
-
3
- require 'benelux'
4
-
5
- a = Benelux.bm(1000000, 5) do
6
- rand
7
- end
8
-
9
- p a
@@ -1,33 +0,0 @@
1
-
2
-
3
- tryouts "Alias method speed", :benchmark do
4
- set :runcount, 1_000
5
-
6
- setup do
7
- module A;
8
- extend self
9
- def meth1; end
10
- def meth2; end
11
- alias_method :meth2_orig, :meth2
12
- def meth2; end
13
- def meth2_with_call; meth2_orig; end
14
- end
15
- end
16
-
17
- [10, 100].each do |mult|
18
- count = runcount * mult
19
-
20
- drill "Natural method (#{count})", count do
21
- A.meth1
22
- end
23
-
24
- drill "Aliased method (#{count})", count do
25
- A.meth2
26
- end
27
-
28
- drill "Aliased method w/ call (#{count})", count do
29
- A.meth2_with_call
30
- end
31
- end
32
-
33
- end
@@ -1,57 +0,0 @@
1
-
2
- xtryouts "Array speed", :benchmark do
3
- set :base, []
4
-
5
- drill "Populate array" do
6
- 10_000_000.times { base << 1 }
7
- end
8
-
9
- drill "with <<" do
10
- a = []
11
- base.each { |v|
12
- a << v
13
- }
14
- a.flatten!
15
- end
16
-
17
- # SLOOOOOWWWWW (b/c it creates a new Array every iteration)
18
- xdrill "with +=" do
19
- a = []
20
- base.each {|v|
21
- a += [v]
22
- }
23
- a
24
- end
25
-
26
- drill "with select" do
27
- a = base.select { |v|
28
- true
29
- }
30
- Array.new(a)
31
- end
32
-
33
- end
34
-
35
-
36
- tryouts "Array merge speed", :benchmark do
37
- set :size, 10_000_000
38
- set :merges, 100_000
39
-
40
- drill "Create #{size} element Array" do
41
- final = []
42
- size.times { final << 1 }
43
- end
44
-
45
- drill "Merge #{size} element Array" do
46
- all = []
47
- msize = size / merges
48
- merges.times do
49
- a = []
50
- msize.times { a << 1 }
51
- all << a
52
- end
53
- final = []
54
- all.each { |a| final.push *a }
55
- end
56
-
57
- end
@@ -1,49 +0,0 @@
1
-
2
-
3
- require 'threadify'
4
-
5
- parallel = 20
6
- runcount = 100_000
7
- baseline = []
8
- testcase = []
9
-
10
- def timer(&blk)
11
- s = Time.now; blk.call; puts ('%.4f' % (Time.now - s).to_f)
12
- end
13
-
14
- print "Populate baseline: "
15
- timer do
16
- parallel.times do
17
- seed = "a"
18
- (runcount).times do
19
- baseline << seed.succ!.clone
20
- end
21
- end
22
- end
23
-
24
- print "Start #{parallel} threads: "
25
- threads = []
26
- timer do
27
- parallel.times do
28
- threads << Thread.new do
29
- seed = "a"
30
- runcount.times { testcase << seed.succ!.clone }
31
- end
32
- end
33
- end
34
-
35
- print "Wait for threads: "
36
- timer do
37
- threads.each { |t| t.join }
38
- end
39
-
40
- # Compare baseline to testcase
41
- p [:size, testcase.size == baseline.size]
42
- p [:sorted, testcase.sort == baseline.sort]
43
-
44
- # Q: Why does the testcase Array seem to repeat perfectly?
45
- # [a,b,c,d,a,b,c,d,a,b,c,d]
46
-
47
- __END__
48
-
49
- Module.method_added?
@@ -1,30 +0,0 @@
1
- group "Benelux Concept Proofs"
2
-
3
- xtryouts "Time benchmarks", :benchmark do
4
- set :runcount, 100000
5
-
6
- drill "Create Array", 1 do
7
- @@timers = []
8
- end
9
-
10
- drill "Time.now overhead", 5 do
11
- runcount.times { Time.now.to_f }
12
- end
13
-
14
- drill "[] << Time.now overhead", 5 do
15
- runcount.times { @@timers << Time.now.to_f }
16
- end
17
-
18
- end
19
-
20
- require 'date'
21
- tryouts "Time proofs", :api do
22
- set :runcount, 100000
23
-
24
- drill "All calls to Time.now.to_f are unique (will fail)", 0 do
25
- timers = []
26
- runcount.times { timers << Time.now.to_f; sleep 0.00000001 }
27
- timers.size - timers.uniq.size
28
- end
29
-
30
- end