diff --git a/spec/performance_tests/add_collection_to_collection_spec.rb b/spec/performance_tests/add_collection_to_collection_spec.rb new file mode 100644 index 00000000..6aa0c119 --- /dev/null +++ b/spec/performance_tests/add_collection_to_collection_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'add collection to collection' do + + describe 'time for each approach' do + it 'should perform consistently across each approach' do + repetitions = 10 + results = [0,0,0] + + 1.upto(repetitions) do |i| + parent_collection1 = Hydra::PCDM::Collection.create + parent_collection2 = Hydra::PCDM::Collection.create + parent_collection3 = Hydra::PCDM::Collection.create + child_collection1 = Hydra::PCDM::Collection.create + child_collection2 = Hydra::PCDM::Collection.create + child_collection3 = Hydra::PCDM::Collection.create + + st = Time.now.to_f + parent_collection1.members << child_collection1 + t = Time.now.to_f - st + results[0] += t + + st = Time.now.to_f + parent_collection2.child_collections = [child_collection2] + t = Time.now.to_f - st + results[1] += t + + st = Time.now.to_f + Hydra::PCDM::AddCollectionToCollection.call( parent_collection3, child_collection3 ) + t = Time.now.to_f - st + results[2] += t + end + + format = "%-20s %11.8f %14.8f\n" + printf("\n\n") + + puts + puts( "============================================" ) + puts( " Adding one collection to a collection (#{repetitions} repetitions)" ) + puts( "============================================" ) + puts( " add approach total time (s) per object time (s)") + puts( "-------------------- -------------- -------------------") + + printf( format,"members <<", results[0], results[0]/repetitions ) + printf( format,"collections=",results[1], results[1]/repetitions ) + printf( format,"service call",results[2], results[2]/repetitions ) + + end + end +end diff --git a/spec/performance_tests/add_object_to_collection_spec.rb b/spec/performance_tests/add_object_to_collection_spec.rb new file mode 100644 index 00000000..d3797056 --- /dev/null +++ b/spec/performance_tests/add_object_to_collection_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'add object to collection' do + + describe 'time for each approach' do + it 'should perform consistently across each approach' do + repetitions = 10 + results = [0,0,0] + + 1.upto(repetitions) do |i| + parent_collection1 = Hydra::PCDM::Collection.create + parent_collection2 = Hydra::PCDM::Collection.create + parent_collection3 = Hydra::PCDM::Collection.create + child_object1 = Hydra::PCDM::Object.create + child_object2 = Hydra::PCDM::Object.create + child_object3 = Hydra::PCDM::Object.create + + st = Time.now.to_f + parent_collection1.members << child_object1 + t = Time.now.to_f - st + results[0] += t + + st = Time.now.to_f + parent_collection2.objects = [child_object2] + t = Time.now.to_f - st + results[1] += t + + st = Time.now.to_f + Hydra::PCDM::AddObjectToCollection.call( parent_collection3, child_object3 ) + t = Time.now.to_f - st + results[2] += t + end + + format = "%-20s %11.8f %14.8f\n" + printf("\n\n") + + puts + puts( "============================================" ) + puts( " Adding one object to a collection (#{repetitions} repetitions)" ) + puts( "============================================" ) + puts( " add approach total time (s) per object time (s)") + puts( "-------------------- -------------- -------------------") + + printf( format,"members <<", results[0], results[0]/repetitions ) + printf( format,"objects=", results[1], results[1]/repetitions ) + printf( format,"service call",results[2], results[2]/repetitions ) + + end + end +end diff --git a/spec/performance_tests/create_collection_spec.rb b/spec/performance_tests/create_collection_spec.rb new file mode 100644 index 00000000..3f7c4b85 --- /dev/null +++ b/spec/performance_tests/create_collection_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe 'create a collection' do + + describe 'time for each approach' do + it 'should perform consistently across each approach' do + repetitions = 10 + results = [0,0] + + 1.upto(repetitions) do |i| + + st = Time.now.to_f + collection1 = Hydra::PCDM::Collection.new + t = Time.now.to_f - st + results[0] += t + + st = Time.now.to_f + collection2 = Hydra::PCDM::Collection.create + t = Time.now.to_f - st + results[1] += t + end + + format = "%-20s %11.8f %14.8f\n" + printf("\n\n") + + puts + puts( "============================================" ) + puts( " Create 1 collection (#{repetitions} repetitions)" ) + puts( "============================================" ) + puts( " create approach total time (s) per object time (s)") + puts( "-------------------- -------------- -------------------") + + printf( format,"new", results[0], results[0]/repetitions ) + printf( format,"create",results[1], results[1]/repetitions ) + + end + end +end diff --git a/spec/performance_tests/repeat_gets_spec.rb b/spec/performance_tests/repeat_gets_spec.rb new file mode 100644 index 00000000..d46c5056 --- /dev/null +++ b/spec/performance_tests/repeat_gets_spec.rb @@ -0,0 +1,112 @@ +require 'spec_helper' + +describe 'repeat_get_related_objects' do + + context 'with large number of related objects files' do + # let(:test_counts) { { 10 => Hydra::PCDM::Collection.create } } + let(:test_counts) { { 10 => Hydra::PCDM::Collection.create, + 50 => Hydra::PCDM::Collection.create, + 100 => Hydra::PCDM::Collection.create + # 1000 => Hydra::PCDM::GenericWork.create + } } + before do + puts( "============================================" ) + puts( " Creating and appending related objects" ) + puts( "============================================" ) + puts( "r_obj count time (s) time/r_obj") + puts( "----------- -------- ----------") + format = "%8d %8.3f %7.3f\n" + + test_counts.each_pair do |related_object_count,collection| + st = Time.now.to_f + related_object_count.times do + Hydra::PCDM::AddRelatedObjectToCollection.call( collection, Hydra::PCDM::Object.create ) + end + t = Time.now.to_f - st + printf( format,10,t,t/related_object_count ) + end + end + + describe 'time for each get approach for various counts of related objects in a collection' do + xit 'should perform consistently across each approach' do + format = "%-20s %11.8f %14.12f\n" + printf("\n\n") + + test_counts.each_pair do |related_object_count,collection| + puts + puts( "============================================" ) + puts( " Getting #{related_object_count} related objects 1 time" ) + puts( "============================================" ) + puts( " get approach time (s) time/r_obj (s)") + puts( "-------------------- ----------- --------------") + + st = Time.now.to_f + collection.related_objects + t = Time.now.to_f - st + printf( format,".related_objects",t,t/related_object_count ) + + st = Time.now.to_f + collection.related_objects.to_a + t = Time.now.to_f - st + printf( format,".related_object.to_a",t,t/related_object_count ) + + st = Time.now.to_f + Hydra::PCDM::GetRelatedObjectsFromCollection.call( collection ) + t = Time.now.to_f - st + printf( format,"service call",t,t/related_object_count ) + end + end + end + end + + context 'with large number of gets' do + describe 'time for repeatedly getting related objects from the same collection' do + let(:related_object_count) { 10 } + let(:collection) { Hydra::PCDM::Collection.create } + # let(:repeat_counts) { [10,50,100,1000] } + let(:repeat_counts) { [10,50,100] } + # let(:repeat_counts) { [10] } + + before do + related_object_count.times do + Hydra::PCDM::AddRelatedObjectToCollection.call( collection, Hydra::PCDM::Object.create ) + end + end + + xit 'should perform consistently across each get approach' do + format = "%-20s %11.8f %14.12f\n" + printf("\n\n") + + repeat_counts.each do |repeat_count| + puts + puts( "============================================" ) + puts( " Getting #{related_object_count} related_objects #{repeat_count} times" ) + puts( "============================================" ) + puts( " get approach time (s) time/get (s)") + puts( "-------------------- ----------- ------------") + + st = Time.now.to_f + repeat_count.times do + collection.related_objects + end + t = Time.now.to_f - st + printf( format,".related_objects",t,t/repeat_count ) + + st = Time.now.to_f + repeat_count.times do + collection.related_objects.to_a + end + t = Time.now.to_f - st + printf( format,".related_object.to_a",t,t/repeat_count ) + + st = Time.now.to_f + repeat_count.times do + Hydra::PCDM::GetRelatedObjectsFromCollection.call( collection ) + end + t = Time.now.to_f - st + printf( format,"service call",t,t/repeat_count ) + end + end + end + end +end