File: compile_template_profile.rb

package info (click to toggle)
ruby-mustache 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 620 kB
  • sloc: ruby: 2,712; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$:.unshift 'lib'

require "ruby-prof"
require 'mustache'
require "pathname"

template = """
{{#products}}
  <div class='product_brick'>
    <div class='container'>
      <div class='element'>
        <img src='images/{{image}}' class='product_miniature' />
      </div>
      <div class='element description'>
        <a href={{url}} class='product_name block bold'>
          {{external_index}}
        </a>
      </div>
    </div>
  </div>
{{/products}}
"""

# Uncomment to measure object allocations. Requires ruby 2.0.0
# RubyProf.measure_mode = RubyProf::ALLOCATIONS

RubyProf.start

20000.times do
  Mustache::Template.new(template).compile
end

result = RubyProf.stop

printer = RubyProf::GraphHtmlPrinter.new(result)

Pathname.new(FileUtils.pwd).join("benchmarks/compile_template_profile.html").open("w+") do |file|
  printer.print(file, {})
end