File: expression_benchmark.rb

package info (click to toggle)
ruby-liquid 5.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,444 kB
  • sloc: ruby: 14,571; makefile: 6
file content (94 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true

require "benchmark/ips"

# benchmark liquid lexing

require 'liquid'

RubyVM::YJIT.enable

STRING_MARKUPS = [
  "\"foo\"",
  "\"fooooooooooo\"",
  "\"foooooooooooooooooooooooooooooo\"",
  "'foo'",
  "'fooooooooooo'",
  "'foooooooooooooooooooooooooooooo'",
]

VARIABLE_MARKUPS = [
  "article",
  "article.title",
  "article.title.size",
  "very_long_variable_name_2024_11_05",
  "very_long_variable_name_2024_11_05.size",
]

NUMBER_MARKUPS = [
  "0",
  "35",
  "1241891024912849",
  "3.5",
  "3.51214128409128",
  "12381902839.123819283910283",
  "123.456.789",
  "-123",
  "-12.33",
  "-405.231",
  "-0",
  "0",
  "0.0",
  "0.0000000000000000000000",
  "0.00000000001",
]

RANGE_MARKUPS = [
  "(1..30)",
  "(1...30)",
  "(1..30..5)",
  "(1.0...30.0)",
  "(1.........30)",
  "(1..foo)",
  "(foo..30)",
  "(foo..bar)",
  "(foo...bar...100)",
  "(foo...bar...100.0)",
]

LITERAL_MARKUPS = [
  nil,
  'nil',
  'null',
  '',
  'true',
  'false',
  'blank',
  'empty',
]

MARKUPS = {
  "string" => STRING_MARKUPS,
  "literal" => LITERAL_MARKUPS,
  "variable" => VARIABLE_MARKUPS,
  "number" => NUMBER_MARKUPS,
  "range" => RANGE_MARKUPS,
}

Benchmark.ips do |x|
  x.config(time: 5, warmup: 5)

  MARKUPS.each do |type, markups|
    x.report("Liquid::Expression#parse: #{type}") do
      markups.each do |markup|
        Liquid::Expression.parse(markup)
      end
    end
  end

  x.report("Liquid::Expression#parse: all") do
    MARKUPS.values.flatten.each do |markup|
      Liquid::Expression.parse(markup)
    end
  end
end