Guest User

Untitled

a guest
Feb 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. require 'rubygems'
  2. require 'builder'
  3. require 'rbench'
  4. require File.dirname(__FILE__) + '/haml/lib/haml'
  5.  
  6. def read(filename)
  7. File.read(File.join(File.dirname(__FILE__), filename))
  8. end
  9.  
  10. RBench.run((ARGV[0] || '10000').to_i) do
  11. column :builder, :title => 'Builder'
  12. column :haml, :title => 'Haml'
  13. column :haml_ugly, :title => 'Haml :ugly'
  14.  
  15. report "Report" do
  16. context = Object.new
  17. context.instance_variable_set('@content', read('lipsum.txt').gsub(/^(.+)$/, '<p>\1</p>'))
  18.  
  19. context.instance_eval(<<RUBY)
  20. def builder
  21. xml = Builder::XmlMarkup.new(:indent => 2)
  22. #{read('builder.builder')}
  23. xml.target!
  24. end
  25. RUBY
  26.  
  27. haml = read('haml.haml')
  28. Haml::Engine.new(haml).def_method(context, :haml)
  29. Haml::Engine.new(haml, :ugly => true).def_method(context, :haml_ugly)
  30.  
  31. builder {context.builder}
  32. haml {context.haml}
  33. haml_ugly {context.haml_ugly}
  34. end
  35. end
Add Comment
Please, Sign In to add comment