summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2024-11-05 09:16:08 +0100
committerJean Boussier <[email protected]>2024-11-05 12:19:55 +0100
commite440268d51fe02b303e3817a7a733a0dac1c5091 (patch)
treeacc87c12fb3495be685fc4ea765803ab2720932e
parent1cb9f9af23538b26e31fa1b3ffd432549af70671 (diff)
Get rid of JSON benchmarks
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11999
-rw-r--r--benchmark/parser.rb39
-rw-r--r--benchmark/standalone.rb41
2 files changed, 0 insertions, 80 deletions
diff --git a/benchmark/parser.rb b/benchmark/parser.rb
deleted file mode 100644
index 1c26ed8d40..0000000000
--- a/benchmark/parser.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require "benchmark/ips"
-require "json"
-require "oj"
-require "rapidjson"
-
-if ENV["ONLY"]
- RUN = ENV["ONLY"].split(/[,: ]/).map{|x| [x.to_sym, true] }.to_h
- RUN.default = false
-elsif ENV["EXCEPT"]
- RUN = ENV["EXCEPT"].split(/[,: ]/).map{|x| [x.to_sym, false] }.to_h
- RUN.default = true
-else
- RUN = Hash.new(true)
-end
-
-def benchmark_parsing(name, json_output)
- puts "== Parsing #{name} (#{json_output.size} bytes)"
-
- Benchmark.ips do |x|
- x.report("json") { JSON.parse(json_output) } if RUN[:json]
- x.report("oj") { Oj.load(json_output) } if RUN[:oj]
- x.report("oj strict") { Oj.strict_load(json_output) } if RUN[:oj]
- x.report("Oj::Parser") { Oj::Parser.usual.parse(json_output) } if RUN[:oj]
- x.report("rapidjson") { RapidJSON.parse(json_output) } if RUN[:rapidjson]
- x.compare!(order: :baseline)
- end
- puts
-end
-
-benchmark_parsing "small nested array", JSON.dump([[1,2,3,4,5]]*10)
-benchmark_parsing "small hash", JSON.dump({ "username" => "jhawthorn", "id" => 123, "event" => "wrote json serializer" })
-
-benchmark_parsing "test from oj", <<JSON
-{"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]]]]]]]}
-JSON
-
-benchmark_parsing "twitter.json", File.read("#{__dir__}/data/twitter.json")
-benchmark_parsing "citm_catalog.json", File.read("#{__dir__}/data/citm_catalog.json")
-benchmark_parsing "canada.json", File.read("#{__dir__}/data/canada.json")
diff --git a/benchmark/standalone.rb b/benchmark/standalone.rb
deleted file mode 100644
index deeb45dcee..0000000000
--- a/benchmark/standalone.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require 'benchmark/ips'
-
-$:.unshift File.expand_path('../ext', __dir__)
-$:.unshift File.expand_path('../lib', __dir__)
-
-bench, mode = ARGV
-
-if mode == 'pure'
- require 'json/pure'
-else
- require 'json/ext'
-end
-
-bench_dump = bench == 'dump'
-if bench_dump
- p JSON.generator
-else
- p JSON.parser
-end
-
-str = File.read("#{__dir__}/data/ohai.json")
-obj = JSON.load(str)
-
-Benchmark.ips do |x|
- unless RUBY_ENGINE == 'ruby'
- x.warmup = 5
- x.iterations = 5
- end
-
- if bench_dump
- x.report('JSON.dump(obj)') do # max_nesting: false, allow_nan: true
- JSON.dump(obj)
- end
- else
- x.report('JSON.load(str)') do # max_nesting: false, allow_nan: true, allow_blank: true, create_additions: true
- JSON.load(str)
- end
- end
-
- x.compare!
-end