Skip to content

Instantly share code, notes, and snippets.

@eqhmcow
Created December 2, 2009 18:39
Show Gist options
  • Save eqhmcow/247426 to your computer and use it in GitHub Desktop.
Save eqhmcow/247426 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
use warnings;
use Benchmark qw(:all);
use YAML::Syck ();
use Data::Dumper ();
use Storable ();
use JSON::XS ();
use YAML::XS ();
my $data = YAML::Syck::LoadFile('yaml.txt');
my $out;
cmpthese(
500,
{
'yaml' => sub {
$out = YAML::XS::Dump($data);
},
'json' => sub {
$out = JSON::XS::encode_json($data);
},
'syck' => sub {
$out = YAML::Syck::Dump($data);
},
'Dumper' => sub {
$out = Data::Dumper::Dumper($data);
},
'Storable' => sub {
$out = Storable::freeze($data);
},
}
);
=pod
Results:
eqhmcow@steve:~$ ./yaml_bench.pl
Rate syck Dumper yaml Storable json
syck 16.1/s -- -4% -5% -88% -93%
Dumper 16.8/s 5% -- -1% -88% -93%
yaml 16.9/s 5% 1% -- -88% -93%
Storable 136/s 749% 711% 707% -- -42%
json 234/s 1355% 1291% 1284% 71% --
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment