Skip to content

Instantly share code, notes, and snippets.

@jgarber
Created October 22, 2009 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarber/216206 to your computer and use it in GitHub Desktop.
Save jgarber/216206 to your computer and use it in GitHub Desktop.
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