Skip to content

Commit e53ee31

Browse files
authored
Merge pull request jhawthorn#7 from casperisfine/improve-benchmarks
Update benchmarks to always compare to stdlib JSON
2 parents cc26805 + 796a342 commit e53ee31

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

benchmark/encoder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ def benchmark_encoding(name, ruby_obj)
1919
puts "== Encoding #{name} (#{json_output.size} bytes)"
2020

2121
Benchmark.ips do |x|
22-
x.report("yajl") { Yajl::Encoder.new.encode(ruby_obj) } if RUN[:yajl]
2322
x.report("json") { JSON.dump(ruby_obj) } if RUN[:json]
23+
x.report("yajl") { Yajl::Encoder.new.encode(ruby_obj) } if RUN[:yajl]
2424
x.report("oj") { Oj.dump(ruby_obj) } if RUN[:oj]
2525
x.report("rapidjson") { RapidJSON.encode(ruby_obj) } if RUN[:rapidjson]
26+
x.compare!(order: :baseline)
2627
end
2728
puts
2829
end

benchmark/parser.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ def benchmark_parsing(name, json_output)
1919
puts "== Parsing #{name} (#{json_output.size} bytes)"
2020

2121
Benchmark.ips do |x|
22-
x.report("yajl") { Yajl::Parser.new.parse(json_output) } if RUN[:yajl]
2322
x.report("json") { JSON.parse(json_output) } if RUN[:json]
23+
x.report("yajl") { Yajl::Parser.new.parse(json_output) } if RUN[:yajl]
2424
x.report("oj") { Oj.load(json_output) } if RUN[:oj]
2525
x.report("oj strict") { Oj.strict_load(json_output) } if RUN[:oj]
2626
x.report("Oj::Parser") { Oj::Parser.usual.parse(json_output) } if RUN[:oj]
2727
x.report("fast_jsonparser") { FastJsonparser.parse(json_output) } if RUN[:fast_jsonparser]
2828
x.report("rapidjson") { RapidJSON.parse(json_output) } if RUN[:rapidjson]
29+
x.compare!(order: :baseline)
2930
end
3031
puts
3132
end

benchmark/validate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def benchmark_parsing(name, json_output)
2121
Benchmark.ips do |x|
2222
x.report("parse") { RapidJSON.parse(json_output) } if RUN[:parse]
2323
x.report("validate") { RapidJSON.valid_json?(json_output) } if RUN[:validate]
24+
x.compare!(order: :baseline)
2425
end
2526
puts
2627
end

0 commit comments

Comments
 (0)