Skip to content

Commit c1c1654

Browse files
committed
Make erubi benchmark compatible with ractors
1 parent bce6aa2 commit c1c1654

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ binarytrees:
5656
ractor: true
5757
erubi:
5858
desc: erubi compiles a simple Erb template into a method with erubi, then times evaluating that method.
59+
ractor: true
5960
etanni:
6061
desc: etanni is an older, extremely simple template-lang format that basically turns your template into an "eval" with a lot of heredocs.
6162
fannkuchredux:

benchmarks/erubi/benchmark.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,26 @@ def check_result_size(result)
4444
source = generate_source(template)
4545

4646
# Create a method with the generated source
47-
eval "# frozen_string_literal: true\ndef run_erb; #{source}; end"
47+
eval <<RUBY
48+
# frozen_string_literal: true
49+
class ErbRenderer
50+
def initialize(values)
51+
@values = values
52+
end
53+
def run_erb
54+
#{source}
55+
end
56+
end
57+
RUBY
4858

4959
# This is taken from actual "gem server" data
50-
@values = JSON.load(File.read "gem_specs.json")
51-
result = run_erb
52-
check_result_size(result)
60+
VALUES = JSON.load(File.read "gem_specs.json")
61+
Ractor.make_shareable(VALUES)
62+
check_result_size(ErbRenderer.new(VALUES).run_erb)
5363

5464
run_benchmark(50) do
5565
250.times do
56-
#result = eval source
57-
result = run_erb
58-
#check_result_size(result)
59-
66+
ErbRenderer.new(VALUES).run_erb
67+
#.then { |result| check_result_size(result) }
6068
end
6169
end

0 commit comments

Comments
 (0)