2010-08-08 11:30:27 +00:00
|
|
|
# require "rubygems"
|
|
|
|
# require "ruby-prof"
|
|
|
|
ENV["RAILS_ENV"] ||= 'test'
|
2010-08-22 23:48:11 +00:00
|
|
|
|
|
|
|
require "./" + File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
|
2010-08-08 11:30:27 +00:00
|
|
|
|
|
|
|
%w{sites pages layouts}.each do |collection|
|
|
|
|
Mongoid.master.collection(collection).drop
|
|
|
|
end
|
|
|
|
|
2010-08-20 00:31:01 +00:00
|
|
|
puts "Starting test..."
|
2010-08-08 11:30:27 +00:00
|
|
|
|
|
|
|
site = Site.create :name => 'Benchmark Website', :subdomain => 'benchmark'
|
|
|
|
|
2010-08-21 22:48:24 +00:00
|
|
|
simple = site.pages.create :title => 'Simple', :slug => 'simple', :raw_template => %{
|
2010-08-08 11:30:27 +00:00
|
|
|
<html>
|
|
|
|
<head></head>
|
|
|
|
<body>
|
|
|
|
<div class="header"></div>
|
|
|
|
<div class="content">
|
|
|
|
<div class="sidebar">
|
2010-08-20 00:31:01 +00:00
|
|
|
A sidebar here / INDEX sidebar
|
2010-08-08 11:30:27 +00:00
|
|
|
</div>
|
|
|
|
<div class="body">
|
2010-08-20 00:31:01 +00:00
|
|
|
<div class="wrapper">Lorem ipsum</div>
|
2010-08-08 11:30:27 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="footer"></div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
}
|
|
|
|
|
2010-08-21 22:48:24 +00:00
|
|
|
base = site.pages.create :title => 'Base page', :slug => 'base', :raw_template => %{
|
2010-08-20 00:31:01 +00:00
|
|
|
<html>
|
|
|
|
<head></head>
|
|
|
|
<body>
|
|
|
|
<div class="header"></div>
|
|
|
|
<div class="content">
|
|
|
|
<div class="sidebar">
|
|
|
|
{% block sidebar %}My simple sidebar{% endblock %}
|
|
|
|
</div>
|
|
|
|
<div class="body">
|
|
|
|
{% block body %}Just to say hi{% endblock %}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="footer"></div>
|
|
|
|
</body>
|
|
|
|
</html>
|
2010-08-08 11:30:27 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 22:48:24 +00:00
|
|
|
page_1 = site.pages.create :title => 'Page 1', :slug => 'page_1', :raw_template => %{
|
2010-08-20 00:31:01 +00:00
|
|
|
{% extends base %}
|
|
|
|
{% block sidebar %}A sidebar here{% endblock %}
|
|
|
|
{% block body %}<div class="wrapper">{% block main %}DEFAULT MAIN CONTENT{% endblock %}</div>{% endblock %}
|
2010-08-08 11:30:27 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 22:48:24 +00:00
|
|
|
page_2 = site.pages.create :title => 'Page 2', :slug => 'page_2', :raw_template => %{
|
2010-08-20 00:31:01 +00:00
|
|
|
{% extends page_1 %}
|
|
|
|
{% block sidebar %}{{ block.super }} / INDEX sidebar{% endblock %}
|
|
|
|
{% block main %}Lorem ipsum{% endblock %}
|
|
|
|
}
|
|
|
|
|
|
|
|
puts "OUTPUT = #{page_2.render(Liquid::Context.new)}"
|
2010-08-08 11:30:27 +00:00
|
|
|
|
2010-08-20 00:31:01 +00:00
|
|
|
context = Liquid::Context.new({}, { 'site' => site }, { :site => site })
|
2010-08-08 11:30:27 +00:00
|
|
|
|
|
|
|
Benchmark.bm do |bm|
|
2010-08-20 00:31:01 +00:00
|
|
|
bm.report("Rendering a simple page 10k times") do
|
|
|
|
10000.times do
|
|
|
|
Page.where(:title => 'Simple').first.render(context)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
bm.report("Rendering a complex page 10k times") do
|
2010-08-08 11:30:27 +00:00
|
|
|
10000.times do
|
2010-08-09 13:51:27 +00:00
|
|
|
Page.last.render(context)
|
2010-08-08 11:30:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-09 13:51:27 +00:00
|
|
|
# # empty page (imac 27'): User System Total Real
|
2010-08-20 00:31:01 +00:00
|
|
|
# Rendering page 10k times 21.390000 1.820000 23.210000 ( 24.120529)
|
2010-08-09 13:51:27 +00:00
|
|
|
|
|
|
|
# # page with inherited template (imac 27'): User System Total Real
|
|
|
|
# Rendering page 10k times 85.840000 7.600000 93.440000 ( 97.841248)
|
2010-08-08 13:16:32 +00:00
|
|
|
|
2010-08-09 13:51:27 +00:00
|
|
|
# # with optimization (imac 27'): User System Total Real
|
2010-08-20 00:31:01 +00:00
|
|
|
# Rendering page 10k times 84.240000 7.280000 91.520000 ( 95.475565)
|
|
|
|
|
|
|
|
# # with locomotive liquid (imac 27'): User System Total Real
|
|
|
|
# Rendering page 10k times 38.750000 3.050000 41.800000 ( 42.880022)
|