#!/usr/bin/perl use strict; use warnings; use XML::Twig; use XML::Simple; use JSON::XS; use YAML::Syck; use Data::Dumper; use Storable; use Fatal qw(open read close); my $xml; while(){ $xml .= $_; } my $twig = XML::Twig->new(); my $href = XMLin($xml); my $dumper = Dumper($href); my $storable = Storable::freeze($href); my $json = encode_json($href); my $yaml = Dump($href); use Benchmark qw( cmpthese ); cmpthese -5, { 'XML::Simple' => sub { XMLin($xml) }, 'XML::Twig' => sub { $twig->parse($xml) }, 'JSON::XS' => sub { decode_json($json) }, 'YAML::Syck' => sub { Load($yaml) }, 'Storable' => sub { Storable::thaw($storable) }, 'Data::Dumper' => sub { eval($dumper) }, }; __DATA__ Basic bread Flour Yeast Water Salt Mix all ingredients together. Knead thoroughly. Cover with a cloth, and leave for one hour in warm room. Knead again. Place in a bread baking tin. Cover with a cloth, and leave for one hour in warm room. Bake in the oven at 180(degrees)C for 30 minutes. #### Rate XML::Simple XML::Twig YAML::Syck Data::Dumper Storable JSON::XS XML::Simple 422/s -- -24% -96% -97% -99% -99% XML::Twig 556/s 32% -- -95% -96% -99% -99% YAML::Syck 11622/s 2652% 1989% -- -11% -81% -84% Data::Dumper 13039/s 2988% 2244% 12% -- -79% -82% Storable 60964/s 14335% 10859% 425% 368% -- -18% JSON::XS 74479/s 17535% 13289% 541% 471% 22% --