From 15430c0770fbd759a52d18790f27b19690f3b335 Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Fri, 24 Oct 2025 09:06:12 +0200 Subject: [PATCH] Add rigid mode to `rake benchmark` task MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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$ ``` --- Rakefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 586b6173..878536bf 100755 --- a/Rakefile +++ b/Rakefile @@ -88,8 +88,13 @@ namespace :benchmark do ruby "./performance/benchmark.rb strict" end - desc "Run the liquid benchmark with both lax and strict parsing" - task run: [:lax, :strict] + 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