From 2f4b5bad26fa6bab09a71c9336c81f79d1736e13 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 5 Nov 2015 13:15:09 +1100 Subject: [PATCH] Make benchmark more realistic --- spec/performance/orders_controller_spec.rb | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index f23b21d05e..e151e4f506 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Spree::OrdersController, type: :controller, performance: true do let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } - let(:products) { (0..9).map { create(:product) } } + let(:products) { (0...num_products).map { create(:product) } } let(:order) { subject.current_order(true) } - let(:num_runs) { 2 } + let(:num_products) { 20 } before do order.set_distribution! distributor, order_cycle @@ -16,26 +16,18 @@ describe Spree::OrdersController, type: :controller, performance: true do describe "adding products to cart" do it "adds products to cart" do - puts "1 product, #{num_runs} times..." - multi_benchmark(3) do - num_runs.times do - expect do - spree_post :populate, variants: {products[0].variants.first.id => 1} - end.to change(Spree::LineItem, :count).by(1) - order.empty! + puts "Pre-populating first product" + spree_post :populate, variants: {products[0].variants.first.id => 1} + + result = Benchmark.measure do + (1..num_products).each do |num_products| + puts "Populating #{num_products} products" + variants = Hash[ products.map { |p| [p.variants.first.id, 1] }.first(num_products) ] + spree_post :populate, variants: variants end end - puts "10 products, #{num_runs} times..." - variants = Hash[ products.map { |p| [p.variants.first.id, 1] } ] - multi_benchmark(3) do - num_runs.times do - expect do - spree_post :populate, variants: variants - end.to change(Spree::LineItem, :count).by(10) - order.empty! - end - end + puts result end end end