-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark.cr
55 lines (46 loc) · 1.11 KB
/
benchmark.cr
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
51
52
53
54
55
require "benchmark"
require "ecr"
require "../src/tree_template"
item = [{name: "red", current: true, url: "#red"},
{name: "green", current: false, url: "#green"},
{name: "blue", current: false, url: "#blue"}]
header = "colors"
template_code : TreeTemplate::Tagger -> Void = ->(t : TreeTemplate::Tagger) {
t.doctype "html5"
t.html do
t.head do
t.title "Simple Benchmark"
end
t.body do
t.h1 header
unless item.empty?
t.ul do
item.each do |i|
t.li { i[:current] ? t.strong i[:name] : t.a i[:name], href: i[:url] }
end
end
else
t.p "The list is empty."
end
end
end
nil
}
class TemplateECR
def item
@item
end
def header
@header
end
def initialize(@header : String, @item : Array(NamedTuple(name: String, current: Bool, url: String))); end
ECR.def_to_s "example/benchmark.ecr"
end
Benchmark.ips do |x|
x.report("render template (html-template)") do
TreeTemplate.new(&template_code).render
end
x.report("render template (ecr)") do
TemplateECR.new(header, item).to_s
end
end