Created
May 28, 2015 17:07
-
-
Save sixfeetover/108afe9b7655e5acea88 to your computer and use it in GitHub Desktop.
Oj vs Yaml
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
Oj: 2.12.8 | |
YAML: 2.0.8 | |
user system total real | |
json 0.400000 0.000000 0.400000 ( 0.405347) | |
json symbolize keys 0.480000 0.000000 0.480000 ( 0.475922) | |
Yaml 31.110000 0.050000 31.160000 ( 31.177862) |
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
require 'benchmark' | |
require 'oj' | |
require 'yaml' | |
puts "Oj: #{Oj::VERSION}" | |
puts "YAML: #{YAML::VERSION}" | |
n = 100_000 | |
data = { | |
key_1: "some string", | |
key_2: 123456789, | |
key_3: { | |
sub_key_1: "xyz 1234" | |
}, | |
key_4: %w{one two three four five} | |
} | |
Benchmark.bm do |x| | |
x.report("json") do | |
n.times {a = Oj.dump(data); Oj.load(a)} | |
end | |
x.report("json symbolize keys") do | |
n.times {a = Oj.dump(data); Oj.load(a, symbolize_keys: true)} | |
end | |
x.report("Yaml") do | |
n.times {a = YAML.dump(data); YAML.load(a)} | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment