aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-10-20 18:51:39 +0200
committerRobert2017-10-20 19:52:33 +0200
commita91d34f1ab09ba90fc0e75d64c091adc74052746 (patch)
tree00ee6be399deba41c4662cc2e77c8f2fe9928fdf
parentdce18aaeaf16a3109b801ba4cd8fd02d0cf564c0 (diff)
downloadchouette-core-a91d34f1ab09ba90fc0e75d64c091adc74052746.tar.bz2
Benchmarks of the stubbed models
Run with N=..., NO_RCOV= bundle exec spring rspec --example 'stubbed' ./spec/models/faster_specs_spec.rb or N=..., NO_RCOV= bundle exec spring rspec --example 'in DB' ./spec/models/faster_specs_spec.rb the benchmark result in seconds were: N: | 10 | 20 | 40 | 80 | ------------+-------+-------+-------+-------+ 'in DB' | 32 | 59 | 116 | 230 | ------------+-------+-------+-------+-------+ 'stubbed' | 3.4 | 3.5 | 3.9 | 4.5 | ------------+-------+-------+-------+-------+ Considering warm up times that gives stubbed ~0.01s/N and in DB ~2.8s/N or a factor of ~280
-rw-r--r--spec/models/faster_specs_spec.rb25
-rw-r--r--spec/support/faster/model_stubber/implementation.rb2
2 files changed, 18 insertions, 9 deletions
diff --git a/spec/models/faster_specs_spec.rb b/spec/models/faster_specs_spec.rb
index 2c97d1055..31f31e0f8 100644
--- a/spec/models/faster_specs_spec.rb
+++ b/spec/models/faster_specs_spec.rb
@@ -1,13 +1,17 @@
RSpec.describe 'Faster Specs', type: :faster do
-
+
+ N = (ENV['N'] || 50).to_i
+
shared_examples_for 'correct behavior' do
- it 'finds workbench' do
- expect( referential.workbench ).to eq(workbench)
- end
+ N.times do
+ it 'finds workbench' do
+ expect( referential.workbench ).to eq(workbench)
+ end
- it 'finds referentials' do
- expect( workbench.referentials ).to eq([referential])
+ it 'finds referentials' do
+ expect( workbench.referentials ).to eq([referential])
+ end
end
end
@@ -15,16 +19,20 @@ RSpec.describe 'Faster Specs', type: :faster do
context 'in DB' do
let( :workbench ){ create :workbench }
let( :referential ){ create(:referential, workbench: workbench) }
-
+
it_behaves_like 'correct behavior'
end
context 'stubbed' do
let( :workbench ){ stub_model Workbench }
let( :referential ){ stub_model( Referential, workbench: workbench ) }
-
+
it_behaves_like 'correct behavior'
+ end
+
+ context 'meta' do
+ let( :workbench ){ stub_model Workbench }
context 'workbench belongs to organisation' do
it 'workbench has no orgnaisation' do
expect( workbench.organisation ).to be_nil
@@ -46,5 +54,6 @@ RSpec.describe 'Faster Specs', type: :faster do
expect( organisation.workbenches ).to be_eql([workbench])
end
end
+
end
end
diff --git a/spec/support/faster/model_stubber/implementation.rb b/spec/support/faster/model_stubber/implementation.rb
index 9ee1f417a..1170629d3 100644
--- a/spec/support/faster/model_stubber/implementation.rb
+++ b/spec/support/faster/model_stubber/implementation.rb
@@ -28,7 +28,7 @@ module ModelStubber
end
def setup_belongs_to reflection, model, key, value
- model.stub(key){value}
+ mystub(model, key){value}
has_manys =
value.class.reflect_on_all_associations(:has_many).select{|v| v.foreign_type == "#{model.class.name.underscore.pluralize}_type" }
has_manys.each do | has_many |