Last active
March 9, 2022 01:47
-
-
Save ggmichaelgo/f108a7ab3327ea68f0afe8ab40366c55 to your computer and use it in GitHub Desktop.
Liquid-C benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a very basic benchmark of Liquid-c rendering. | |
# Tested with | |
# Ryzen 5 2600 | |
# 32GB Ram | |
# Ubuntu 18.04.6 LTS | |
require "benchmark/ips" | |
require "liquid" | |
require "liquid/c" | |
liquid_template = <<END | |
{% for product in products %} | |
<div class='product_brick'> | |
<div class='container'> | |
<div class='element'> | |
<img src='images/{{ product.image }}' class='product_miniature' /> | |
</div> | |
<div class='element description'> | |
<a href={{ product.url }} class='product_name block bold'> | |
{{ product.external_index }} | |
</a> | |
</div> | |
</div> | |
</div> | |
{% endfor %} | |
END | |
data = { | |
'products' => 100.times.map do |n| | |
{ 'image' => "foo-#{rand 100}.png", 'url' => "http://bar-#{rand 100}.com", 'external_index' => "FOO #{rand 100}" } | |
end | |
} | |
def render_liquid(template, data) | |
Liquid::Template.parse(template).render(data) | |
end | |
liquid_template_pre = Liquid::Template.parse(liquid_template) | |
def render_liquid_pre(tmpl, data) | |
tmpl.render(data) | |
end | |
Benchmark.ips do |x| | |
x.report('render_liquid') { render_liquid(liquid_template, data) } | |
x.report('render_liquid_pre') { render_liquid_pre(liquid_template_pre, data) } | |
end |
Mustache vs Liquid
Warming up --------------------------------------
render_mustache 99.000 i/100ms
render_mustache_pre 165.000 i/100ms
render_liquid 89.000 i/100ms
render_liquid_pre 95.000 i/100ms
Calculating -------------------------------------
render_mustache 989.726 (± 1.4%) i/s - 4.950k in 5.002351s
render_mustache_pre 1.655k (± 1.6%) i/s - 8.415k in 5.087024s
render_liquid 903.586 (± 0.9%) i/s - 4.539k in 5.023754s
render_liquid_pre 978.205 (± 2.4%) i/s - 4.940k in 5.053165s
Comparison:
render_mustache_pre: 1654.6 i/s
render_mustache: 989.7 i/s - 1.67x (± 0.00) slower
render_liquid_pre: 978.2 i/s - 1.69x (± 0.00) slower
render_liquid: 903.6 i/s - 1.83x (± 0.00) slower
Mustache vs Liquid-C
Warming up --------------------------------------
render_mustache 100.000 i/100ms
render_mustache_pre 168.000 i/100ms
render_liquid 91.000 i/100ms
render_liquid_pre 97.000 i/100ms
Calculating -------------------------------------
render_mustache 997.077 (± 1.5%) i/s - 5.000k in 5.015802s
render_mustache_pre 1.691k (± 0.8%) i/s - 8.568k in 5.066910s
render_liquid 908.254 (± 1.0%) i/s - 4.550k in 5.010059s
render_liquid_pre 983.415 (± 0.7%) i/s - 4.947k in 5.030669s
Comparison:
render_mustache_pre: 1691.1 i/s
render_mustache: 997.1 i/s - 1.70x (± 0.00) slower
render_liquid_pre: 983.4 i/s - 1.72x (± 0.00) slower
render_liquid: 908.3 i/s - 1.86x (± 0.00) slower
Mustache vs mg-const-table
Warming up --------------------------------------
render_mustache 98.000 i/100ms
render_mustache_pre 165.000 i/100ms
render_liquid 376.000 i/100ms
render_liquid_pre 429.000 i/100ms
Calculating -------------------------------------
render_mustache 981.643 (± 1.9%) i/s - 4.998k in 5.093392s
render_mustache_pre 1.664k (± 0.7%) i/s - 8.415k in 5.058266s
render_liquid 3.750k (± 1.1%) i/s - 18.800k in 5.014307s
render_liquid_pre 4.281k (± 1.3%) i/s - 21.450k in 5.011499s
Comparison:
render_liquid_pre: 4280.9 i/s
render_liquid: 3749.7 i/s - 1.14x (± 0.00) slower
render_mustache_pre: 1663.7 i/s - 2.57x (± 0.00) slower
render_mustache: 981.6 i/s - 4.36x (± 0.00) slower
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Liquid-C 4.0.0
Liquid-C 4.1.0