Skip to content

@jrafanie /gist:2936844
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Psych 8 times slower than Syck for YAML.load?
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)
@metaskills

My results

*** Testing: ruby 1.9.3p125 (2012-02-16) [x86_64-darwin11.3.0] ***
                                user     system      total        real
YAML.load:                  0.180000   0.000000   0.180000 (  0.192219)
Hash#to_yaml:               0.450000   0.010000   0.460000 (  0.468074)
YAML.load(syck):            0.050000   0.000000   0.050000 (  0.060273)
Hash#to_yaml(syck):         0.390000   0.000000   0.390000 (  0.390994)
@jrafanie
Owner

Apparently, this is fixed in this commit tenderlove/psych@0845b07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.