Skip to content

Commit 7ea4bdb

Browse files
committed
Annotate benchmarks
1 parent 4271115 commit 7ea4bdb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

benchmark/parser.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ 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 strict") { Oj.strict_load(json_output) } if RUN[:oj]
2322
x.report("Oj::Parser") { Oj::Parser.usual.parse(json_output) } if RUN[:oj]
2423
x.report("rapidjson") { RapidJSON.parse(json_output) } if RUN[:rapidjson]
2524
x.compare!(order: :baseline)
2625
end
2726
puts
2827
end
2928

29+
# Oj::Parser is very significanly faster (2.70x) on the nested array benchmark
30+
# thanks to its stack implementation that saves resizing arrays.
3031
benchmark_parsing "small nested array", JSON.dump([[1,2,3,4,5]]*10)
32+
33+
# Oj::Parser is significanly faster (~1.5x) on the next 4 benchmarks
34+
# in large part thanks to its string caching.
35+
# Other than that we're either a bit slower or a bit faster than regular `Oj.load`.
3136
benchmark_parsing "small hash", JSON.dump({ "username" => "jhawthorn", "id" => 123, "event" => "wrote json serializer" })
3237

3338
benchmark_parsing "test from oj", <<JSON
@@ -36,4 +41,9 @@ def benchmark_parsing(name, json_output)
3641

3742
benchmark_parsing "twitter.json", File.read("#{__dir__}/data/twitter.json")
3843
benchmark_parsing "citm_catalog.json", File.read("#{__dir__}/data/citm_catalog.json")
39-
benchmark_parsing "canada.json", File.read("#{__dir__}/data/canada.json")
44+
45+
# rapidjson is 8x faster thanks to it's much more performant float parser.
46+
# Unfortunately, there isn't a lot of existing fast float parsers in pure C,
47+
# and including C++ is problematic.
48+
# Aside from that, we're faster than other alternatives here.
49+
benchmark_parsing "float parsing", File.read("#{__dir__}/data/canada.json")

0 commit comments

Comments
 (0)