mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
adding in markaby benchmarks
git-svn-id: svn://hamptoncatlin.com/haml/trunk@547 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
7c60d34454
commit
77d09a5aea
2 changed files with 65 additions and 1 deletions
|
@ -5,7 +5,9 @@ require 'rubygems'
|
|||
require 'active_support'
|
||||
require 'action_view'
|
||||
require 'benchmark'
|
||||
require 'markaby'
|
||||
require 'stringio'
|
||||
require 'open-uri'
|
||||
|
||||
module Haml
|
||||
class Benchmarker
|
||||
|
@ -14,6 +16,7 @@ module Haml
|
|||
# directory.
|
||||
def initialize(base = File.dirname(__FILE__))
|
||||
ActionView::Base.register_template_handler("haml", Haml::Template)
|
||||
ActionView::Base.register_template_handler("mab", Markaby::Template)
|
||||
unless base.class == ActionView::Base
|
||||
@base = ActionView::Base.new(base)
|
||||
else
|
||||
|
@ -29,19 +32,27 @@ module Haml
|
|||
template_name = 'standard'
|
||||
haml_template = "haml/templates/#{template_name}"
|
||||
rhtml_template = "haml/rhtml/#{template_name}"
|
||||
markaby_template = File.dirname(__FILE__) + "/haml/markaby/#{template_name}.mab"
|
||||
markaby_template_data = open(markaby_template).read
|
||||
sass_template = File.dirname(__FILE__) + "/sass/templates/complex.sass"
|
||||
|
||||
old_stdout = $stdout
|
||||
$stdout = StringIO.new
|
||||
|
||||
|
||||
times = Benchmark.bmbm do |b|
|
||||
b.report("haml:") { runs.times { @base.render haml_template } }
|
||||
b.report("erb:") { runs.times { @base.render rhtml_template } }
|
||||
b.report("mab:") { runs.times {
|
||||
Markaby::Template.new(markaby_template_data).render
|
||||
#@base.render markaby_template
|
||||
} }
|
||||
end
|
||||
|
||||
#puts times[0].inspect, times[1].inspect
|
||||
ratio = sprintf("%g", times[0].to_a[5] / times[1].to_a[5])
|
||||
mab_ratio = sprintf("%g", times[2].to_a[5] / times[1].to_a[5])
|
||||
puts "Haml/ERB: " + ratio
|
||||
puts "Mab/Haml: " + mab_ratio
|
||||
|
||||
puts '', '-' * 50, 'Sass on its own', '-' * 50
|
||||
|
||||
|
|
53
test/haml/markaby/standard.mab
Normal file
53
test/haml/markaby/standard.mab
Normal file
|
@ -0,0 +1,53 @@
|
|||
self << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
|
||||
html(:xmlns=>'http://www.w3.org/1999/xhtml', 'xml:lang'=>'en-US') do
|
||||
head do
|
||||
title "Hampton Catlin Is Totally Awesome"
|
||||
meta("http-equiv" => "Content-Type", :content => "text/html; charset=utf-8")
|
||||
end
|
||||
body do
|
||||
# You're In my house now!
|
||||
concat("Foo")
|
||||
div :class => "header" do
|
||||
self << %|Yes, ladies and gentileman. He is just that egotistical.
|
||||
Fantastic! This should be multi-line output
|
||||
The question is if this would translate! Ahah!|
|
||||
self << 1 + 9 + 8 + 2 #numbers should work and this should be ignored
|
||||
end
|
||||
div(:id => "body") { self << "Quotes should be loved! Just like people!"}
|
||||
120.times do |number|
|
||||
number
|
||||
end
|
||||
self << "Wow.|"
|
||||
p do
|
||||
self << "Holy cow " +
|
||||
"multiline " +
|
||||
"tags! " +
|
||||
"A pipe (|) even!"
|
||||
self << [1, 2, 3].collect { |n| "PipesIgnored|" }
|
||||
self << [1, 2, 3].collect { |n|
|
||||
n.to_s
|
||||
}.join("|")
|
||||
end
|
||||
div(:class => "silent") do
|
||||
foo = String.new
|
||||
foo << "this"
|
||||
foo << " shouldn't"
|
||||
foo << " evaluate"
|
||||
self << foo + " but now it should!"
|
||||
# Woah crap a comment!
|
||||
end
|
||||
# That was a line that shouldn't close everything.
|
||||
ul(:class => "really cool") do
|
||||
('a'..'f').each do |a|
|
||||
li a
|
||||
end
|
||||
end
|
||||
div((@should_eval = "with this text"), :id => "combo", :class => "of_divs_with_underscore")
|
||||
[ 104, 101, 108, 108, 111 ].map do |byte|
|
||||
byte.chr
|
||||
end
|
||||
div(:class => "footer") do
|
||||
strong("This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works", :class => "shout")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue