At Defensio, we recently needed to find out how slow YAML was compared to Marshal. We also wanted to know how much faster ZAML, an alternative to YAML, is.
I ran a few benchmarks under 1.8.7 MRI, 1.8.7 REE, 1.9.2 and Rubinius to see how they compare. I also benchmarked to_json to have an order of magnitude. My benchmarks consist of serializing/deserializing a relatively complex Hash (many nested levels). The YAML representation of the Hash is ~3kb.
YAML is really slow
YAML is twice as fast under 1.9.2 vs 1.8.7
ZAML is much faster than YAML under 1.8.7, but about the same in 1.9.2
REE (no GC tweaks) isn’t faster in this situation
Rubinius is ridiculously slow
Psych under Ruby 1.9.2 is disappointing
Here are the results:
If you want to benchmark on your machine, here’s the source code. Sorry, I couldn’t include the YAML string as it is confidential data.