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 hidden or 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mustache vs Liquid
Mustache vs Liquid-C
Mustache vs mg-const-table