Skip to content

Commit

Permalink
Benchmark Oj::Parser in a thread safe way
Browse files Browse the repository at this point in the history
The documentation state `Oj::Parser.usual` isn't thread safe:
https://github.com/ohler55/oj/blob/c70bf4125b546bc7146840b15de36460d42b4dff/ext/oj/parser.c#L1507-L1513

As such we shouldn't benchark it this way, but instantiate a new
parser every time. Technically in real world scenarios you could
create a pool of parsers and re-use them, but if it's not provided
by the gem, I'm not sure we should go out of our way to do it.
  • Loading branch information
byroot committed Nov 8, 2024
1 parent b1397e2 commit 7952782
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion benchmark/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def benchmark_parsing(name, json_output)
Benchmark.ips do |x|
x.report("json") { JSON.parse(json_output) } if RUN[:json]
x.report("oj") { Oj.load(json_output) } if RUN[:oj]
x.report("Oj::Parser") { Oj::Parser.usual.parse(json_output) } if RUN[:oj]
x.report("Oj::Parser") { Oj::Parser.new(:usual).parse(json_output) } if RUN[:oj]
x.report("rapidjson") { RapidJSON.parse(json_output) } if RUN[:rapidjson]
x.compare!(order: :baseline)
end
Expand Down

0 comments on commit 7952782

Please # to comment.