Created
June 15, 2012 14:54
-
-
Save jrafanie/2936844 to your computer and use it in GitHub Desktop.
Psych 8 times slower than Syck for YAML.load?
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 'yaml' | |
yaml_str = <<-eos | |
--- | |
hardware: | |
include: | |
volumes: | |
columns: | |
- name | |
- free_space_percent | |
- free_space | |
- size | |
- used_space_percent | |
- used_space | |
- filesystem | |
managed: | |
columns: | |
- department | |
storage: | |
columns: | |
- name | |
eos | |
h = nil | |
n = 1_000 | |
puts "*** Testing: #{RUBY_DESCRIPTION} ***" | |
Benchmark.bm(25) do |x| | |
GC.start | |
x.report("YAML.load:") { n.times { h = YAML.load(yaml_str) } } | |
GC.start | |
x.report("Hash#to_yaml:") { n.times { h.to_yaml } } | |
if RUBY_VERSION == "1.9.3" | |
require 'syck' | |
YAML::ENGINE.yamler = 'syck' | |
GC.start | |
x.report("YAML.load(syck):") { n.times { YAML.load(yaml_str) } } | |
GC.start | |
x.report("Hash#to_yaml(syck):") { n.times { h.to_yaml } } | |
end | |
end | |
Example output: | |
*** Testing: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0] *** | |
user system total real | |
YAML.load: 0.300000 0.090000 0.390000 ( 0.389299) | |
Hash#to_yaml: 0.430000 0.000000 0.430000 ( 0.426713) | |
YAML.load(syck): 0.050000 0.000000 0.050000 ( 0.056971) | |
Hash#to_yaml(syck): 0.400000 0.000000 0.400000 ( 0.405698) | |
*** Testing: ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-darwin11.3.0] *** | |
user system total real | |
YAML.load: 0.050000 0.000000 0.050000 ( 0.053337) | |
Hash#to_yaml: 0.640000 0.030000 0.670000 ( 0.673445) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My results