user system total real
handlebars 25.512891 0.134474 25.647365 ( 26.928544)
liquid 1.622490 0.009660 1.632150 ( 1.656763)
erb 2.215501 0.017284 2.232785 ( 2.550151)
gsub 0.050991 0.000783 0.051774 ( 0.055585)
Last active
January 4, 2022 11:16
-
-
Save mbajur/6aa3a4189f4aba15f985672f87ab9f40 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' |
Good catch! I will update that in a bit
Edit: labels and results updated
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone is planing to run this benchmark: The labels are flipped. The label for liquid is actually running handlebars and the label for handlebars is actually running liquid.