| 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 |
|
| 26 |
|
| 27 |
RubyProf.start |
| 28 |
|
| 29 |
20000.times do |
| 30 |
Mustache::Template.new(template).compile |
| 31 |
end |
| 32 |
|
| 33 |
result = RubyProf.stop |
| 34 |
|
| 35 |
printer = RubyProf::GraphHtmlPrinter.new(result) |
| 36 |
|
| 37 |
Pathname.new(FileUtils.pwd).join("benchmarks/compile_template_profile.html").open("w+") do |file| |
| 38 |
printer.print(file, {}) |
| 39 |
end |