Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It looked up one by one to make sure that the supported options were included in passed options. This approach of looking up the passed hash each time has an overhead. This patch will extract key and value from the passed options using `rb_hash_foreach()` and check if they are supported or not. − | before | after | result -- | -- | -- | -- Oj.load | 381.671k | 419.917k | 1.10x Oj.dump | 507.221k | 578.877k | 1.14x ### Environment - MacBook Air (M1, 2020) - macOS 12.0 beta 3 - Apple M1 - Ruby 3.0.2 ### Before ``` Warming up -------------------------------------- Oj.load 38.287k i/100ms Oj.dump 51.076k i/100ms Calculating ------------------------------------- Oj.load 381.671k (± 0.6%) i/s - 1.914M in 5.015868s Oj.dump 507.221k (± 0.5%) i/s - 2.554M in 5.035014s ``` ### After ``` Warming up -------------------------------------- Oj.load 42.352k i/100ms Oj.dump 58.022k i/100ms Calculating ------------------------------------- Oj.load 419.917k (± 0.5%) i/s - 2.118M in 5.043048s Oj.dump 578.877k (± 0.4%) i/s - 2.901M in 5.011700s ``` ### Test code ```ruby require 'benchmark/ips' require 'oj' 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.report('Oj.load') { Oj.load(json, symbol_keys: true) } data = Oj.load(json, symbol_keys: true) x.report('Oj.dump') { Oj.dump(json, mode: :compat) } end ```
- Loading branch information
1 parent
62aea59
commit 89eb430
Showing
1 changed file
with
103 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters