-
Notifications
You must be signed in to change notification settings - Fork 8
/
runBenchmarks.nim
59 lines (46 loc) · 1.24 KB
/
runBenchmarks.nim
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
56
57
58
59
## Simple benchmarking using a template similar to
## https://github.com/mustache/mustache/blob/master/benchmarks/render_template_profile.rb
import json
import times
import moustachu
let templ = """
{{#products}}
<div class='product_brick'>
<div class='container'>
<div class='element'>
<img src='images/{{image.file}}' class='{{image.class}}' />
</div>
<div class='element description'>
<a href="{{url}}" class='product_name block bold'>
{{external_index}}
</a>
</div>
</div>
</div>
{{/products}}
"""
let product = %* {
"external_index": "product",
"url": "/products/7",
"image": {
"file": "products/product.jpg",
"class": "product_miniature"
}
}
var data = parseJson(""" { "products": [] } """)
for i in 1..200:
data["products"].add(product)
let start = epochTime()
var result = ""
for i in 1..2000:
var ctx = newContext(data)
result = templ.render(ctx)
let t = epochTime() - start
# echo result
echo "Avg context creation and render time (s): ", t / 2000.0
# 0.07263176703453064s nested sections
# 0.0699 merge
# 0.066979 no recursion
# 0.15766 with pcre (sometimes 0.1618221524953842)
# 0.135369 with tokenizer
# 0.02034837448596954 w/ tokenizer on release