public
Last active

Psych 8 times slower than Syck for YAML.load?

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
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)

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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.