mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[ruby/json] Restore the simple standlone benchmark for iterating
7b68800991
This commit is contained in:
parent
d10e09b7e3
commit
615a087216
2 changed files with 1257 additions and 0 deletions
1216
benchmark/data/ohai.json
Normal file
1216
benchmark/data/ohai.json
Normal file
File diff suppressed because it is too large
Load diff
41
benchmark/standalone.rb
Normal file
41
benchmark/standalone.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue