user system total real
liquid 26.567868 0.136828 26.704696 ( 27.704823)
handlebars 1.579311 0.005023 1.584334 ( 1.613605)
erb 2.157431 0.007026 2.164457 ( 2.187186)
gsub 0.047701 0.000408 0.048109 ( 0.055053)
-
-
Save lucasprag/ca9868fb8e3438e915e039197bbd8f54 to your computer and use it in GitHub Desktop.
Liquid, Handlebars, Erb and gsub benchmarks
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
require 'rubygems' | |
require 'benchmark' | |
require 'ruby-handlebars' | |
require 'cgi' | |
require 'liquid' | |
require 'erb' | |
input = ("a".."z").map { |letter| [letter, letter] }.to_h | |
n = 50_000 | |
hbs = Handlebars::Handlebars.new | |
Benchmark.bm do |benchmark| | |
benchmark.report("handlebars") do | |
n.times do | |
hbs.compile("Hello {{name}}").call({ name: 'world' }) | |
end | |
end | |
benchmark.report("liquid") do | |
n.times do | |
Liquid::Template.parse("Hello {{name}}").render({ name: 'world' }) | |
end | |
end | |
benchmark.report("erb") do | |
n.times do | |
ERB.new("Hello <%= name %>").result_with_hash({ name: 'world' }) | |
end | |
end | |
benchmark.report("gsub") do | |
n.times do | |
"Hello {{name}}".gsub('{{name}}', 'world') | |
end | |
end | |
end |
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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem 'liquid' | |
gem 'ruby-handlebars' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @lucasprag, I believe the name of the reports are swapped: you're reporting liquid for the handlebars results and viceversa