jgarber (owner)

Revisions

gist: 216206 Download_button fork
public
Public Clone URL: git://gist.github.com/216206.git
Embed All Files: show embed
Radiant eager loading benchmark.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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