vorpal 0.0.6.rc2 → 0.0.6.rc3

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.
@@ -0,0 +1,192 @@
1
+ require 'integration_spec_helper'
2
+ require 'vorpal'
3
+ require 'virtus'
4
+ require 'activerecord-import/base'
5
+
6
+ describe 'performance' do
7
+
8
+ class Bug
9
+ include Virtus.model
10
+
11
+ attribute :id, Integer
12
+ attribute :name, String
13
+ attribute :lives_on, Object
14
+ end
15
+
16
+ class Tree; end
17
+
18
+ class Trunk
19
+ include Virtus.model
20
+
21
+ attribute :id, Integer
22
+ attribute :length, Decimal
23
+ attribute :bugs, Array[Bug]
24
+ attribute :tree, Tree
25
+ end
26
+
27
+ class Branch
28
+ include Virtus.model
29
+
30
+ attribute :id, Integer
31
+ attribute :length, Decimal
32
+ attribute :tree, Tree
33
+ attribute :branches, Array[Branch]
34
+ attribute :bugs, Array[Bug]
35
+
36
+ def add_branch(branch_options)
37
+ branch = Branch.new(branch_options.merge(branch: self))
38
+ branches << branch
39
+ branch
40
+ end
41
+ end
42
+
43
+ class Tree
44
+ include Virtus.model
45
+
46
+ attribute :id, Integer
47
+ attribute :name, String
48
+ attribute :trunk, Trunk
49
+ attribute :branches, Array[Branch]
50
+
51
+ def set_trunk(trunk)
52
+ trunk.tree = self
53
+ self.trunk = trunk
54
+ end
55
+
56
+ def add_branch(branch_options)
57
+ branch = Branch.new(branch_options.merge(tree: self))
58
+ branches << branch
59
+ branch
60
+ end
61
+ end
62
+
63
+ before(:all) do
64
+ define_table('branches_perf', {length: :decimal, tree_id: :integer, branch_id: :integer}, false)
65
+ BranchDB = defineAr('branches_perf')
66
+
67
+ define_table('bugs_perf', {name: :text, lives_on_id: :integer, lives_on_type: :string}, false)
68
+ BugDB = defineAr('bugs_perf')
69
+
70
+ define_table('trees_perf', {name: :text, trunk_id: :integer}, false)
71
+ TreeDB = defineAr('trees_perf')
72
+
73
+ define_table('trunks_perf', {length: :decimal}, false)
74
+ TrunkDB = defineAr('trunks_perf')
75
+ end
76
+
77
+ let(:test_repository) { build_repository }
78
+
79
+ # Vorpal 0.0.5:
80
+ # user system total real
81
+ # create 4.160000 0.440000 4.600000 ( 6.071752)
82
+ # update 7.990000 0.730000 8.720000 ( 15.281017)
83
+ # load 10.120000 0.730000 10.850000 ( 21.087785)
84
+ # destroy 6.090000 0.620000 6.710000 ( 12.541420)
85
+ #
86
+ # Vorpal 0.0.6:
87
+ # user system total real
88
+ # create 0.990000 0.100000 1.090000 ( 1.415715)
89
+ # update 2.240000 0.180000 2.420000 ( 2.745321)
90
+ # load 2.130000 0.020000 2.150000 ( 2.223182)
91
+ # destroy 0.930000 0.010000 0.940000 ( 1.038624)
92
+ it 'benchmarks all operations' do
93
+ trees = build_trees(1000)
94
+ Benchmark.bm(7) do |x|
95
+ x.report("create") { test_repository.persist_all(trees) }
96
+ x.report("update") { test_repository.persist_all(trees) }
97
+ x.report("load") { ids = trees.map(&:id); test_repository.load_all(ids, Tree) }
98
+ x.report("destroy") { test_repository.destroy_all(trees) }
99
+ end
100
+ end
101
+
102
+ it 'persists aggregates quickly' do
103
+ trees = build_trees(1000)
104
+
105
+ puts 'starting persistence benchmark'
106
+ puts Benchmark.measure {
107
+ test_repository.persist_all(trees)
108
+ }
109
+ end
110
+
111
+ it 'updates aggregates quickly' do
112
+ trees = build_trees(1000)
113
+
114
+ test_repository.persist_all(trees)
115
+
116
+ puts 'starting update benchmark'
117
+ puts Benchmark.measure {
118
+ test_repository.persist_all(trees)
119
+ }
120
+ end
121
+
122
+ it 'loads aggregates quickly' do
123
+ trees = build_trees(1000)
124
+ test_repository.persist_all(trees)
125
+ ids = trees.map(&:id)
126
+
127
+ puts 'starting loading benchmark'
128
+ puts Benchmark.measure {
129
+ test_repository.load_all(ids, Tree)
130
+ }
131
+ end
132
+
133
+ it 'destroys aggregates quickly' do
134
+ trees = build_trees(1000)
135
+ test_repository.persist_all(trees)
136
+
137
+ puts 'starting destruction benchmark'
138
+ puts Benchmark.measure {
139
+ test_repository.destroy_all(trees)
140
+ }
141
+ end
142
+
143
+ def build_trees(count)
144
+ (1..count).map do |i|
145
+ tree = Tree.new
146
+ trunk = Trunk.new(length: i)
147
+ tree.set_trunk(trunk)
148
+
149
+ branch1 = tree.add_branch(length: i * 10)
150
+ branch2 = tree.add_branch(length: i * 20)
151
+ branch2.add_branch(length: i * 30)
152
+
153
+ build_bug(trunk)
154
+ build_bug(branch1)
155
+
156
+ tree
157
+ end
158
+ end
159
+
160
+ def build_bug(bug_home)
161
+ bug = Bug.new(lives_on: bug_home)
162
+ bug_home.bugs = [bug]
163
+ end
164
+
165
+ def build_repository
166
+ Vorpal.define do
167
+ map Tree do
168
+ fields :name
169
+ belongs_to :trunk
170
+ has_many :branches
171
+ end
172
+
173
+ map Trunk do
174
+ fields :length
175
+ has_one :tree
176
+ has_many :bugs, fk: :lives_on_id, fk_type: :lives_on_type
177
+ end
178
+
179
+ map Branch do
180
+ fields :length
181
+ belongs_to :tree
182
+ has_many :bugs, fk: :lives_on_id, fk_type: :lives_on_type
183
+ has_many :branches
184
+ end
185
+
186
+ map Bug do
187
+ fields :name
188
+ belongs_to :lives_on, fk: :lives_on_id, fk_type: :lives_on_type, child_classes: [Trunk, Branch]
189
+ end
190
+ end
191
+ end
192
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vorpal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6.rc2
4
+ version: 0.0.6.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kirby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_serializer
@@ -150,11 +150,14 @@ files:
150
150
  - lib/vorpal/util/array_hash.rb
151
151
  - lib/vorpal/util/hash_initialization.rb
152
152
  - lib/vorpal/version.rb
153
+ - spec/helpers/db_helpers.rb
153
154
  - spec/integration_spec_helper.rb
154
155
  - spec/unit_spec_helper.rb
155
156
  - spec/vorpal/aggregate_repository_spec.rb
156
157
  - spec/vorpal/class_config_builder_spec.rb
158
+ - spec/vorpal/configs_spec.rb
157
159
  - spec/vorpal/identity_map_spec.rb
160
+ - spec/vorpal/performance_spec.rb
158
161
  - vorpal.gemspec
159
162
  homepage: https://github.com/nulogy/vorpal
160
163
  licenses:
@@ -181,8 +184,11 @@ signing_key:
181
184
  specification_version: 4
182
185
  summary: Separate your domain model from your persistence mechanism.
183
186
  test_files:
187
+ - spec/helpers/db_helpers.rb
184
188
  - spec/integration_spec_helper.rb
185
189
  - spec/unit_spec_helper.rb
186
190
  - spec/vorpal/aggregate_repository_spec.rb
187
191
  - spec/vorpal/class_config_builder_spec.rb
192
+ - spec/vorpal/configs_spec.rb
188
193
  - spec/vorpal/identity_map_spec.rb
194
+ - spec/vorpal/performance_spec.rb