Debian Codegraph @

benchmarks/render_template_profile.rb

raw symbols SCIP
1 $:.unshift 'lib'
2
3 require "ruby-prof"
4 require 'mustache'
5 require "pathname"
6
7 template = """
8 {{#products}}
9 <div class='product_brick'>
10 <div class='container'>
11 <div class='element'>
12 <img src='images/{{image}}' class='product_miniature' />
13 </div>
14 <div class='element description'>
15 <a href={{url}} class='product_name block bold'>
16 {{external_index}}
17 </a>
18 </div>
19 </div>
20 </div>
21 {{/products}}
22 """
23
24
25 data = {
26 products: []
27 }
28
29 200.times do
30 data[:products] << {
31 :external_index=>"product",
32 :url=>"/products/7",
33 :image=>"products/product.jpg"
34 }
35 end
36
37 template = Mustache::Template.new(template)
38
39 # Uncomment to measure object allocations. Requires ruby 2.0.0
40 # RubyProf.measure_mode = RubyProf::ALLOCATIONS
41
42 RubyProf.start
43
44 2000.times do
45 ctx = Mustache::Context.new(Mustache.new); ctx.push(data)
46 template.render(ctx)
47 end
48
49 result = RubyProf.stop
50
51 printer = RubyProf::GraphHtmlPrinter.new(result)
52
53 Pathname.new(FileUtils.pwd).join("benchmarks/render_template_profile.html").open("w+") do |file|
54 printer.print(file, {})
55 end