Skip to content

Commit 2333912

Browse files
committed
Update benchmark notes
1 parent 2625e8c commit 2333912

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

benchmark/parser.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,21 @@ 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 very significanly faster (2.70x) on the nested array benchmark
32-
# thanks to its stack implementation that saves resizing arrays.
33-
# But we're on par with `Oj.dumo`
31+
# Oj::Parser is very significanly faster (1.80x) on the nested array benchmark.
3432
benchmark_parsing "small nested array", JSON.dump([[1,2,3,4,5]]*10)
3533

36-
# Oj::Parser is significanly faster (~1.5x) on the next 4 benchmarks in large part thanks to its string caching.
37-
38-
# Other than that we're either a bit slower or a bit faster than regular `Oj.load`.
34+
# Oj::Parser is significanly faster (~1.5x) on the next 4 benchmarks in large part because its
35+
# cache is persisted across calls. That's not something we can do with the current API, we'd
36+
# need to expose a stateful API as well, but that's no really desirable.
37+
# Other than that we're faster than regular `Oj.load` by a good margin.
3938
benchmark_parsing "small hash", JSON.dump({ "username" => "jhawthorn", "id" => 123, "event" => "wrote json serializer" })
4039

4140
benchmark_parsing "test from oj", <<JSON
4241
{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}
4342
JSON
4443

45-
# On these two more realistic benchmarks, still significanlty slower than alternatives.
46-
# Caching of keys is likely required to be able to match performance.
47-
# On the twitter and activitypub payloads the difference isn't that big (~10%)
48-
# but on citm_catalog it's up to a 50% difference.
44+
# On these macro-benchmarks, we're on par with `Oj::Parser` and significantly
45+
# faster than `Oj.load`.
4946
benchmark_parsing "activitypub.json", File.read("#{__dir__}/data/activitypub.json")
5047
benchmark_parsing "twitter.json", File.read("#{__dir__}/data/twitter.json")
5148
benchmark_parsing "citm_catalog.json", File.read("#{__dir__}/data/citm_catalog.json")

0 commit comments

Comments
 (0)