Refactor in where obtain hash keys by using common function. However, it might have the margin of error for the overhead of calling oj_calc_hash_key().
−
before
after
result
Oj.dump
449.521k
447.738k
0.996x
Environment
Linux
Manjaro Linux x86_64
Kernel: 6.3.5-2-MANJARO
AMD Ryzen 7 5800H
gcc version 13.1.1
Ruby 3.2.2
Before
Warming up --------------------------------------
Oj.load 44.738k i/100ms
Calculating -------------------------------------
Oj.load 449.521k (± 0.9%) i/s - 6.755M in 15.029388s
After
Warming up --------------------------------------
Oj.load 44.117k i/100ms
Calculating -------------------------------------
Oj.load 447.738k (± 0.3%) i/s - 6.750M in 15.075672s
Test code
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'benchmark-ips'
gem 'oj'
end
json =<<-EOF
{
"$id": "https://example.com/person.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string",
"description": "The person's first name."
},
"lastName": {
"type": "string",
"description": "The person's last name."
},
"age": {
"description": "Age in years which must be equal to or greater than zero.",
"type": "integer",
"minimum": 0
}
}
}
EOF
Benchmark.ips do |x|
x.warmup = 5
x.time = 15
x.report('Oj.load') { Oj.load(json, mode: :compat) }
end
Refactor in where obtain hash keys by using common function. However, it might have the margin of error for the overhead of calling oj_calc_hash_key().
Environment
Before
After
Test code