-
-
Save bastjan/e69a103480da720cd3d3 to your computer and use it in GitHub Desktop.
Benchmark different ruby serializing options
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 'rubygems' | |
require 'json' | |
require 'yaml' | |
include Benchmark | |
benchmark_iterations = 1 | |
large_single_dimension_array = [42, 123.123] * 5000 | |
large_single_dimension_hash = {} | |
10000.times do |i| | |
large_single_dimension_hash["key#{i}".intern] = i | |
end | |
benchmark do |t| | |
t.report("array marshal") do | |
benchmark_iterations.times { | |
Marshal.load(Marshal.dump(large_single_dimension_array)) | |
} | |
end | |
t.report("array json ") do | |
benchmark_iterations.times { | |
JSON.load(JSON.dump(large_single_dimension_array)) | |
} | |
end | |
t.report("array yaml ") do | |
benchmark_iterations.times { | |
YAML.load(YAML.dump(large_single_dimension_array)) | |
} | |
end | |
t.report("hash marshal ") do | |
benchmark_iterations.times { | |
Marshal.load(Marshal.dump(large_single_dimension_hash)) | |
} | |
end | |
t.report("hash json ") do | |
benchmark_iterations.times { | |
JSON.load(JSON.dump(large_single_dimension_hash)) | |
} | |
end | |
t.report("hash yaml ") do | |
benchmark_iterations.times { | |
YAML.load(YAML.dump(large_single_dimension_hash)) | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment