Created
January 29, 2023 14:44
-
-
Save luke-gru/adf7468fbc0a3807b5f9a875fcfce116 to your computer and use it in GitHub Desktop.
JSON parse tight loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'benchmark' | |
RACTORS = ARGV.first == "ractor" | |
J = { rand => rand }.to_json | |
Ractor.make_shareable(J) | |
iterations = 1_000_000 | |
Benchmark.bmbm do |x| | |
x.report("json parse#{RACTORS ? ' (ractors)' : ''}") { | |
if RACTORS | |
rs = [] | |
10.times.each do | |
rs << Ractor.new(iterations) do |iters| | |
i = 0 | |
iters = iters / 10 | |
while i < iters | |
JSON.parse(J) | |
i+=1 | |
end | |
end | |
end | |
rs.each(&:take) | |
else | |
i = 0 | |
while i < iterations | |
JSON.parse(J) | |
i+=1 | |
end | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment