benelux 0.3.2 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,42 @@
2
2
  group "Benelux"
3
3
 
4
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
+ drill "[] and filter are the same", true do
26
+ base.filter(:even => false) == base.filter(:even => false)
27
+ end
28
+
29
+ dream :class, SelectableArray
30
+ dream :object_id, base.object_id
31
+ dream :size, 5
32
+ drill "filter! makes permanent changes to itself" do
33
+ base.filter! :even => true
34
+ end
35
+
36
+ end
37
+
38
+
5
39
  tryouts "Tags" do
6
- set :base, Benelux::Tags[:a => 1, :b => 2]
40
+ set :base, Selectable::Tags[:a => 1, :b => 2]
7
41
 
8
42
  drill "Can equal a Hash with the same keys/values", true do
9
43
  base == {:a => 1, :b => 2}
@@ -57,4 +91,6 @@ tryouts "Tags" do
57
91
  base <= [2, 1]
58
92
  end
59
93
 
60
- end
94
+ end
95
+
96
+
@@ -0,0 +1,23 @@
1
+ #
2
+ # group "Benelux"
3
+ #
4
+ # library :benelux, 'lib'
5
+ # tryouts "Selectable::Global" do
6
+ # set :bast, Benelux::Counts.new
7
+ # setup do
8
+ #
9
+ # end
10
+ #
11
+ # dream :class, Benelux::Counts
12
+ # dream :names, [:group1, :group2]
13
+ # drill "Add groups" do
14
+ # bast.add_group :group1, :group2
15
+ # bast
16
+ # end
17
+ #
18
+ # drill "Add objects to groups", true do
19
+ # bast.send(:group1).class
20
+ # bast.class.group_class
21
+ # end
22
+ #
23
+ # end
@@ -0,0 +1,106 @@
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
23
+
24
+ __END__
25
+ # OLD (0.3):
26
+
27
+ tryouts "Essentials" do
28
+
29
+ setup do
30
+ class ::Sleeper
31
+ def do_something() sleep rand/3 end
32
+ def another_method(t) t*2 end
33
+ end
34
+ end
35
+
36
+ drill "Add timers to existing objects", true do
37
+ Benelux.add_timer Sleeper, :do_something
38
+ Sleeper.new.respond_to? :timeline
39
+ end
40
+
41
+ dream :class, SelectableArray
42
+ dream :size, 1
43
+ dream :proc, lambda { |obj|
44
+ pm = obj.first
45
+ pm.class == Benelux::MethodTimer &&
46
+ pm.meth == :do_something &&
47
+ pm.klass == Sleeper
48
+ }
49
+ drill "Keeps a list of modified methods" do
50
+ Benelux.packed_methods
51
+ end
52
+
53
+ drill "Knows what a timer has been defined", true do
54
+ Benelux.timed_method? :Sleeper, :do_something
55
+ end
56
+
57
+ drill "Knows what a timer has not been defined", false do
58
+ Benelux.timed_method? :Sleeper, :no_such_method
59
+ end
60
+
61
+ dream :class, SelectableArray
62
+ drill "A Benelux object has a timed_methods method" do
63
+ s = Sleeper.new
64
+ s.do_something
65
+ s.timed_methods
66
+ end
67
+
68
+ end
69
+
70
+ tryouts "Counters" do
71
+ setup do
72
+ class ::Sleeper
73
+ def do_something() sleep rand/3 end
74
+ def another_method(t) t*2 end
75
+ end
76
+ end
77
+ drill "Add timers to existing objects", true do
78
+ Benelux.add_counter Sleeper, :another_method do |args,ret|
79
+ ret
80
+ end
81
+ Sleeper.new.respond_to? :timeline
82
+ end
83
+ dream :kind_of?, Benelux::MethodPacker
84
+ drill "Can get specific packed method" do
85
+ Benelux.packed_method Sleeper, :another_method
86
+ end
87
+
88
+ dream :class, Benelux::Count
89
+ dream :name, :another_method
90
+ dream :to_i, 2000
91
+ drill "Run counter" do
92
+ a = Sleeper.new
93
+ a.another_method(1000)
94
+ pm = Benelux.packed_method Sleeper, :another_method
95
+ Benelux.thread_timeline.counts.first
96
+ end
97
+ end
98
+
99
+ xtryouts "Not supported" do
100
+
101
+ dream :exception, Benelux::NotSupported
102
+ drill "Class is not supported" do
103
+ Benelux.add_timer Class, :new
104
+ end
105
+
106
+ end
@@ -0,0 +1,34 @@
1
+ group "Benelux"
2
+
3
+ library :benelux, 'lib'
4
+ tryouts "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,19 +1,40 @@
1
1
 
2
+
3
+ __END__
4
+ # OLD (0.3):
5
+
2
6
  group "Benelux"
3
7
 
4
8
  library :benelux, 'lib'
5
9
  tryouts "Timelines" do
6
10
  set :tl, Benelux::Timeline.new
7
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
+
8
29
  dream :class, Benelux::Timeline
9
30
  dream :size, 3
10
31
  drill "create timeline with marks" do
11
32
  tl.add_default_tags :a => :frog
12
- tl.add_mark(:one) and sleep rand
33
+ tl.add_mark(:one)
13
34
  tl.add_default_tags :b => :rest
14
- tl.add_mark(:two) and sleep rand
35
+ tl.add_mark(:two)
15
36
  tl.add_default_tags :c => :tilt
16
- tl.add_mark(:three) and sleep rand
37
+ tl.add_mark(:three)
17
38
  tl.marks
18
39
  end
19
40
 
@@ -22,4 +43,18 @@ tryouts "Timelines" do
22
43
  tl[:frog][:b => :rest]
23
44
  end
24
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
25
60
  end
@@ -0,0 +1,33 @@
1
+
2
+ tryouts "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
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.3.2
4
+ version: 0.4.1
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: 2009-10-02 00:00:00 -04:00
12
+ date: 2009-10-06 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,17 +39,28 @@ files:
39
39
  - Rakefile
40
40
  - benelux.gemspec
41
41
  - lib/benelux.rb
42
+ - lib/benelux/count.rb
42
43
  - lib/benelux/mark.rb
44
+ - lib/benelux/mixins/symbol.rb
43
45
  - lib/benelux/mixins/thread.rb
46
+ - lib/benelux/packer.rb
44
47
  - lib/benelux/range.rb
48
+ - lib/benelux/reporter.rb
45
49
  - lib/benelux/stats.rb
46
- - lib/benelux/tags.rb
47
50
  - lib/benelux/timeline.rb
51
+ - lib/benelux/track.rb
52
+ - lib/selectable.rb
53
+ - lib/selectable/global.rb
54
+ - lib/selectable/object.rb
55
+ - lib/selectable/tags.rb
48
56
  - tryouts/10_stats_tryouts.rb
49
- - tryouts/11_tags_tryouts.rb
50
- - tryouts/20_class_methods_tryouts.rb
57
+ - tryouts/11_selectable_tryouts.rb
58
+ - tryouts/12_selectable_global_tryouts.rb
59
+ - tryouts/20_tracks_tryouts.rb
60
+ - tryouts/30_reporter_tryouts.rb
51
61
  - tryouts/30_timeline_tryouts.rb
52
62
  - tryouts/proofs/alias_performance.rb
63
+ - tryouts/proofs/array_performance.rb
53
64
  - tryouts/proofs/timer_threading.rb
54
65
  has_rdoc: true
55
66
  homepage: http://github.com/delano/benelux
@@ -1,69 +0,0 @@
1
-
2
- group "Benelux"
3
-
4
- library :benelux, 'lib'
5
-
6
- tryouts "Basics" do
7
-
8
- setup do
9
- class ::Sleeper
10
- def do_something() sleep rand/3 end
11
- end
12
- end
13
-
14
- drill "Add timers to existing objects", true do
15
- Benelux.add_timer Sleeper, :do_something
16
- Sleeper.new.respond_to? :timeline
17
- end
18
-
19
- dream :class, Hash
20
- dream { Hash[ Sleeper => [:do_something] ] }
21
- drill "Benelux keeps track of timed objects" do
22
- Benelux.timed_methods
23
- end
24
-
25
- dream [:do_something]
26
- drill "A Benelux object has a benelux_timers method" do
27
- Sleeper.new.benelux_timers
28
- end
29
-
30
- dream :class, Benelux::Timeline
31
- dream :size, 10 # 5 * 2 = 10 (marks are stored for the method start and end)
32
- drill "Creates a timeline" do
33
- sleeper = Sleeper.new
34
- 5.times { sleeper.do_something }
35
- sleeper.timeline
36
- end
37
-
38
- dream :size, 4
39
- drill "Timelines are stored per object" do
40
- sleeper = Sleeper.new
41
- Thread.new do
42
- 2.times { sleeper.do_something }
43
- end.join
44
- sleeper.timeline
45
- end
46
-
47
- dream :class, Benelux::Timeline
48
- dream :size, 10
49
- drill "Creates a timeline for the thread" do
50
- Benelux.thread_timeline
51
- end
52
-
53
- dream :class, Benelux::Timeline
54
- dream :size, 14
55
- drill "Creates a global timeline" do
56
- Benelux.timeline
57
- end
58
-
59
- end
60
-
61
-
62
- tryouts "Not supported" do
63
-
64
- dream :exception, Benelux::NotSupported
65
- drill "Class is not supported" do
66
- Benelux.add_timer Class, :new
67
- end
68
-
69
- end