Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to benchmark two cases of self referential many to many as described in datamapper associations. Both cases consist of an Item clss, which may require many other items. In both cases, I required the ruby benchmark library and source file, created two items and benchmarked require/unrequie functions as below:

Benchmark.bmbm do |x|
  x.report("require:")   { item_1.require_item item_2, 10 }
  x.report("unrequire:")   { item_1.unrequire_item item_2 }
end

To be clear, both functions are datamapper add/modify functions like:

componentMaps.create :component_id => item.id, :quantity => quantity
componentMaps.all(:component_id => item.id).destroy!

and

links_to_components.create :component_id => item.id, :quantity => quantity
links_to_components.all(:component_id => item.id).destroy!

The results are variable and in the range of 0.018001 to 0.022001 for require function in both cases, and 0.006 to 0.01 for unrequire function in both cases. This made me suspicious about the correctness of my test method.

Edit

I went ahead and compared a "get by primary key case" to a "finding first matching record case" by:

(1..10000).each do |i|
  Item.create :name => "item_#{i}"
end

Benchmark.bmbm do |x|
  x.report("Get") { item = Item.get 9712 }
  x.report("First") { item = Item.first :name => "item_9712" }
end

where the results were very different like 0 sec compared to 0.0312, as expected. This suggests that the benchmarking works.

I wonder whether I benchmarked the two types of associations correctly, and whether a difference between 0.018 and 0.022 sec significant?

share|improve this question
2  
Not quite sure what you're asking. Getting different performance on laptop vs hosting would be expected due to different hardware. Why would this suggest that your methods are not correct? –  Matt Gibson Nov 5 '12 at 15:42
    
Thank you for pointing that out. I wasn't mentioning the difference between my laptop and hosting. It's my bad that I mentioned this useless info, and I removed it. I am not proficient in SQL, and since results of my benchmark came out tobe very similar, I wonder if I used the correct technique for this comparison. I mean, maybe I needed to compare cases of mass modify instead of simple read/writes to see the real difference. –  barerd Nov 5 '12 at 20:09
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.