File: render_lambda_benchmark.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 (50 lines) | stat: -rw-r--r-- 805 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
40
41
42
43
44
45
46
47
48
49
50
$:.unshift "lib"

require "mustache"
require "benchmark/ips"

BASE_TEMPLATE = <<end_of_template
<h2>Lambdas</h2>
{{#lambdas}}
  {{#lambda}}
    Here is some text inside the lambda.\n
    Also a variable is present: {{name}}.
  {{/lambda}}
{{/lambdas}}
end_of_template

one_name = [
  {
    name: "Charlie Chaplin",
    lambda: lambda {|text| "\n--\n#{text}\n--\n" }
  },
]

data_10 = {
  lambdas: one_name * 10,
}

data_100 = {
  lambdas: one_name * 100,
}

data_1000 = {
  lambdas: one_name * 1000,
}

mustache = Mustache.new
mustache.template = BASE_TEMPLATE

Benchmark.ips do |x|
  x.report("render list of 10") do
    mustache.render(data_10)
  end

  x.report("render list of 100") do
    mustache.render(data_100)
  end

  x.report("render list of 1000") do
    mustache.render(data_1000)
  end
end