Created
November 1, 2012 22:52
-
-
Save Zapotek/3997262 to your computer and use it in GitHub Desktop.
Simple benchmark of Marshal 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
# | |
# Test done on: Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz | |
# | |
require 'yaml' | |
TIMES = 1000 | |
obj = [] | |
500.times { |i| obj << { 'key' * i => [ 'value' * i ] } } | |
yaml_dump_time = Time.now | |
TIMES.times { s = YAML.dump( obj ) } | |
yaml_dump_time = Time.now - yaml_dump_time | |
s = nil | |
yaml_load_time = Time.now | |
TIMES.times { YAML.dump( s ) } | |
yaml_load_time = Time.now - yaml_load_time | |
marshal_dump_time = Time.now | |
TIMES.times { s = Marshal.dump( obj ) } | |
marshal_dump_time = Time.now - marshal_dump_time | |
marshal_load_time = Time.now | |
TIMES.times { Marshal.dump( s ) } | |
marshal_load_time = Time.now - marshal_load_time | |
puts "YAML dump time: #{yaml_dump_time}" | |
#=> YAML dump time: 43.353922509 | |
puts "YAML load time: #{yaml_load_time}" | |
#=> YAML load time: 0.033819831 | |
puts "Marshal dump time: #{marshal_dump_time}" | |
#=> Marshal dump time: 1.106293497 | |
puts "Marshal load time: #{marshal_load_time}" | |
#=> Marshal load time: 0.141277654 | |
puts "Marshal dumps #{yaml_dump_time/Float( marshal_dump_time )} times faster." | |
#=> Marshal dumps 39.188445585701565 times faster. | |
puts "Marshal loads #{yaml_load_time/Float( marshal_load_time )} times faster." | |
#=> Marshal loads 0.23938556482541817 times faster. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment