Files
liquid/fluid-bench/benchmark.rb
Sam Doiron ba82f8d05e Perf: Remove unneeded to_s and freeze strings
- No longer call to_s on string literals passed to undefined filters
- Freeze all string literals at the top of the generated code

This shows a ~9% performance improvement on the fluid benchmark when run without YJIT
2022-04-20 11:03:36 -03:00

27 lines
740 B
Ruby

# https://github.com/evanphx/benchmark-ips
require 'liquid'
#require 'liquid/c'
require 'benchmark/ips'
require_relative '../lib/liquid/compile'
require_relative 'shop_filter'
require_relative 'money_filter'
# Each database table is a hash
require_relative 'database'
tables = Database.tables
Liquid::Template.register_filter(MoneyFilter)
Liquid::Template.register_filter(ShopFilter)
@template = Liquid::Template.parse(File.read("product.liquid"))
context = Liquid::Context.new([tables, {}], {}, {}, false, Liquid::ResourceLimits.new(Liquid::Template.default_resource_limits))
Benchmark.ips do |x|
x.report("render") { @template.render(context) }
# Compare the iterations per second of the various reports
x.compare!
end