Skip to content

Commit 821b92e

Browse files
authored
Merge pull request #703 from casperisfine/oj-parser-thread-safe
Benchmark `Oj::Parser` in a thread safe way
2 parents b1397e2 + 855563f commit 821b92e

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

benchmark/parser.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def benchmark_parsing(name, json_output)
1919
Benchmark.ips do |x|
2020
x.report("json") { JSON.parse(json_output) } if RUN[:json]
2121
x.report("oj") { Oj.load(json_output) } if RUN[:oj]
22-
x.report("Oj::Parser") { Oj::Parser.usual.parse(json_output) } if RUN[:oj]
22+
x.report("Oj::Parser") { Oj::Parser.new(:usual).parse(json_output) } if RUN[:oj]
2323
x.report("rapidjson") { RapidJSON.parse(json_output) } if RUN[:rapidjson]
2424
x.compare!(order: :baseline)
2525
end
@@ -28,10 +28,6 @@ def benchmark_parsing(name, json_output)
2828

2929
# NB: Notes are based on ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [arm64-darwin23]
3030

31-
# Oj::Parser is significanly faster (~1.3x) on the next 3 micro-benchmarks in large part because its
32-
# cache is persisted across calls. That's not something we can do with the current API, we'd
33-
# need to expose a stateful API as well, but that's no really desirable.
34-
# Other than that we're faster than regular `Oj.load` by a good margin (between 1.3x and 2.4x).
3531
benchmark_parsing "small nested array", JSON.dump([[1,2,3,4,5]]*10)
3632
benchmark_parsing "small hash", JSON.dump({ "username" => "jhawthorn", "id" => 123, "event" => "wrote json serializer" })
3733
benchmark_parsing "test from oj", <<JSON

0 commit comments

Comments
 (0)