Created
October 22, 2009 19:24
-
-
Save jgarber/216206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../spec_helper' | |
require 'benchmark' | |
class DeepChildPagesDataset < Dataset::Base | |
uses :home_page | |
def load | |
create_page "Parent" do | |
1.upto(50) do |num| | |
create_page "Child #{num}" do | |
create_page_part "child_#{num}_body".symbolize, :name => "body", :content => "Child #{num} body." | |
create_page_part "child_#{num}_extended".symbolize, :name => "extended", :content => "extended!" | |
create_page "Grandchild #{num}.1" do | |
create_page "Great Grandchild #{num}.1.1" | |
end | |
end | |
end | |
end | |
end | |
end | |
describe "Standard Tags" do | |
dataset :deep_child_pages | |
it "benchmarks loading of children parts" do | |
Benchmark.bmbm do|b| | |
b.report("eager loading") do | |
@page = pages(:parent) | |
10.times do | |
children = @page.children.find(:all, :include => :parts, :conditions => {:page_parts => {:name => 'body'}}) | |
children.each do |child| | |
body_part = child.parts.to_a.find {|p| p.name == 'body' } | |
end | |
end | |
end | |
b.report("normal loading") do | |
@page = pages(:parent) | |
10.times do | |
children = @page.children | |
children.each do |child| | |
child.part('body') | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment