require 'bundler/setup' require 'benchmark' require 'musterb' require 'mustache' require 'erubis' template = <<-EOF {{#products}}

Product: {{name}}

{{/products}} EOF # Mix of symbols and strings def random_product { :id => rand(10000), :favorite_id => rand(10000), :quick_view_url => "http://foo.bar", :name => "Product name", :url => "http://foo.url", :thumbnail => "http://foo.image", :sku => "sku", :fabrics => "fabrics", :price => "price", :themes => "themes", :designer => "designer", :favorited => "favorited" } end products = 16.times.map { random_product } mustache = lambda { Mustache.render(template, :products => products) } erb = Musterb.to_erb(template) compiled_erb = Erubis::Eruby.new(erb) musterb = lambda { compiled_erb.result(:products => products) } if mustache.call == musterb.call puts "mustache and musterb are identical" else puts "mustache and musterb differ (this will usually be whitespace)" puts "mustache:" puts mustache.call puts "--------------------------------------------------------------------------------" puts "musterb:" puts musterb.call puts "--------------------------------------------------------------------------------" end Benchmark.bmbm do |x| x.report("mustache") { 1000.times { mustache.call } } x.report("musterb") { 1000.times { musterb.call } } end