mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
The benchmark results show that rigid mode performs a bit better than both strict
and lax modes across most metrics, including tokenization, parsing, rendering,
and their combined operations. Rigid mode consistently delivers the highest
number of iterations per second, with performance differences staying within
1–2% compared to the other modes
```
================================================================================
/opt/rubies/3.4.1/bin/ruby ./performance/benchmark.rb lax
Running benchmark for 20 seconds (with 10 seconds warmup).
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
tokenize: 332.000 i/100ms
parse: 14.000 i/100ms
render: 61.000 i/100ms
parse & render: 11.000 i/100ms
Calculating -------------------------------------
tokenize: 3.325k (± 1.0%) i/s (300.73 μs/i) - 66.732k in 20.070562s
parse: 148.166 (± 0.7%) i/s (6.75 ms/i) - 2.968k in 20.032971s
render: 654.428 (± 4.0%) i/s (1.53 ms/i) - 13.115k in 20.090452s
parse & render: 116.108 (± 1.7%) i/s (8.61 ms/i) - 2.332k in 20.089221s
================================================================================
/opt/rubies/3.4.1/bin/ruby ./performance/benchmark.rb strict
Running benchmark for 20 seconds (with 10 seconds warmup).
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
tokenize: 332.000 i/100ms
parse: 14.000 i/100ms
render: 61.000 i/100ms
parse & render: 11.000 i/100ms
Calculating -------------------------------------
tokenize: 3.332k (± 0.2%) i/s (300.14 μs/i) - 66.732k in 20.029095s
parse: 145.674 (± 0.0%) i/s (6.86 ms/i) - 2.926k in 20.086104s
render: 656.711 (± 4.6%) i/s (1.52 ms/i) - 13.115k in 20.050810s
parse & render: 114.705 (± 0.0%) i/s (8.72 ms/i) - 2.299k in 20.043028s
================================================================================
/opt/rubies/3.4.1/bin/ruby ./performance/benchmark.rb rigid
Running benchmark for 20 seconds (with 10 seconds warmup).
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23]
Warming up --------------------------------------
tokenize: 333.000 i/100ms
parse: 14.000 i/100ms
render: 62.000 i/100ms
parse & render: 11.000 i/100ms
Calculating -------------------------------------
tokenize: 3.334k (± 0.3%) i/s (299.93 μs/i) - 66.933k in 20.075484s
parse: 148.349 (± 2.0%) i/s (6.74 ms/i) - 2.968k in 20.019775s
render: 663.752 (± 2.6%) i/s (1.51 ms/i) - 13.268k in 20.010303s
parse & render: 116.464 (± 2.6%) i/s (8.59 ms/i) - 2.332k in 20.037869s
liquid$
```
151 lines
3.5 KiB
Ruby
Executable File
151 lines
3.5 KiB
Ruby
Executable File
# frozen_string_literal: true
|
|
|
|
require 'rake'
|
|
require 'rake/testtask'
|
|
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
|
|
require "liquid/version"
|
|
|
|
task(default: [:test, :rubocop])
|
|
|
|
desc('run test suite with default parser')
|
|
Rake::TestTask.new(:base_test) do |t|
|
|
t.libs << 'lib' << 'test'
|
|
t.test_files = FileList['test/{integration,unit}/**/*_test.rb']
|
|
t.verbose = false
|
|
end
|
|
|
|
Rake::TestTask.new(:integration_test) do |t|
|
|
t.libs << 'lib' << 'test'
|
|
t.test_files = FileList['test/integration/**/*_test.rb']
|
|
t.verbose = false
|
|
end
|
|
|
|
desc('run test suite with warn error mode')
|
|
task :warn_test do
|
|
ENV['LIQUID_PARSER_MODE'] = 'warn'
|
|
Rake::Task['base_test'].invoke
|
|
end
|
|
|
|
task :rubocop do
|
|
if RUBY_ENGINE == 'ruby'
|
|
require 'rubocop/rake_task'
|
|
RuboCop::RakeTask.new
|
|
end
|
|
end
|
|
|
|
desc('runs test suite with lax, strict, and rigid parsers')
|
|
task :test do
|
|
ENV['LIQUID_PARSER_MODE'] = 'lax'
|
|
Rake::Task['base_test'].invoke
|
|
|
|
ENV['LIQUID_PARSER_MODE'] = 'strict'
|
|
Rake::Task['base_test'].reenable
|
|
Rake::Task['base_test'].invoke
|
|
|
|
ENV['LIQUID_PARSER_MODE'] = 'rigid'
|
|
Rake::Task['base_test'].reenable
|
|
Rake::Task['base_test'].invoke
|
|
|
|
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'truffleruby'
|
|
ENV['LIQUID_PARSER_MODE'] = 'lax'
|
|
Rake::Task['integration_test'].reenable
|
|
Rake::Task['integration_test'].invoke
|
|
|
|
ENV['LIQUID_PARSER_MODE'] = 'strict'
|
|
Rake::Task['integration_test'].reenable
|
|
Rake::Task['integration_test'].invoke
|
|
|
|
ENV['LIQUID_PARSER_MODE'] = 'rigid'
|
|
Rake::Task['integration_test'].reenable
|
|
Rake::Task['integration_test'].invoke
|
|
end
|
|
end
|
|
|
|
task(gem: :build)
|
|
task :build do
|
|
system "gem build liquid.gemspec"
|
|
end
|
|
|
|
task install: :build do
|
|
system "gem install liquid-#{Liquid::VERSION}.gem"
|
|
end
|
|
|
|
task release: :build do
|
|
system "git tag -a v#{Liquid::VERSION} -m 'Tagging #{Liquid::VERSION}'"
|
|
system "git push --tags"
|
|
system "gem push liquid-#{Liquid::VERSION}.gem"
|
|
system "rm liquid-#{Liquid::VERSION}.gem"
|
|
end
|
|
|
|
namespace :benchmark do
|
|
desc "Run the liquid benchmark with lax parsing"
|
|
task :lax do
|
|
ruby "./performance/benchmark.rb lax"
|
|
end
|
|
|
|
desc "Run the liquid benchmark with strict parsing"
|
|
task :strict do
|
|
ruby "./performance/benchmark.rb strict"
|
|
end
|
|
|
|
desc "Run the liquid benchmark with rigid parsing"
|
|
task :rigid do
|
|
ruby "./performance/benchmark.rb rigid"
|
|
end
|
|
|
|
desc "Run the liquid benchmark with lax, strict, and rigid parsing"
|
|
task run: [:lax, :strict, :rigid]
|
|
|
|
desc "Run unit benchmarks"
|
|
namespace :unit do
|
|
task :all do
|
|
Dir["./performance/unit/*_benchmark.rb"].each do |file|
|
|
puts "🧪 Running #{file}"
|
|
ruby file
|
|
end
|
|
end
|
|
|
|
task :lexer do
|
|
Dir["./performance/unit/lexer_benchmark.rb"].each do |file|
|
|
puts "🧪 Running #{file}"
|
|
ruby file
|
|
end
|
|
end
|
|
|
|
task :expression do
|
|
Dir["./performance/unit/expression_benchmark.rb"].each do |file|
|
|
puts "🧪 Running #{file}"
|
|
ruby file
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
namespace :profile do
|
|
desc "Run the liquid profile/performance coverage"
|
|
task :run do
|
|
ruby "./performance/profile.rb"
|
|
end
|
|
|
|
desc "Run the liquid profile/performance coverage with strict parsing"
|
|
task :strict do
|
|
ruby "./performance/profile.rb strict"
|
|
end
|
|
end
|
|
|
|
namespace :memory_profile do
|
|
desc "Run memory profiler"
|
|
task :run do
|
|
ruby "./performance/memory_profile.rb"
|
|
end
|
|
end
|
|
|
|
desc("Run example")
|
|
task :example do
|
|
ruby "-w -d -Ilib example/server/server.rb"
|
|
end
|
|
|
|
task :console do
|
|
exec 'irb -I lib -r liquid'
|
|
end
|