@@ -28,24 +28,21 @@ def benchmark_parsing(name, json_output)
28
28
29
29
# NB: Notes are based on ruby 3.3.4 (2024-07-09 revision be1089c8ec) +YJIT [arm64-darwin23]
30
30
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.
34
32
benchmark_parsing "small nested array" , JSON . dump ( [ [ 1 , 2 , 3 , 4 , 5 ] ] *10 )
35
33
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.
39
38
benchmark_parsing "small hash" , JSON . dump ( { "username" => "jhawthorn" , "id" => 123 , "event" => "wrote json serializer" } )
40
39
41
40
benchmark_parsing "test from oj" , <<JSON
42
41
{"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]]]]]]]}
43
42
JSON
44
43
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`.
49
46
benchmark_parsing "activitypub.json" , File . read ( "#{ __dir__ } /data/activitypub.json" )
50
47
benchmark_parsing "twitter.json" , File . read ( "#{ __dir__ } /data/twitter.json" )
51
48
benchmark_parsing "citm_catalog.json" , File . read ( "#{ __dir__ } /data/citm_catalog.json" )
0 commit comments