Skip to content

Instantly share code, notes, and snippets.

@Craftworks
Created September 26, 2010 12:57
Show Gist options
  • Save Craftworks/597906 to your computer and use it in GitHub Desktop.
Save Craftworks/597906 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Benchmark ':all';
use Data::Dumper;
use Data::Dump;
use Data::MessagePack;
use JSON::XS;
my $data = [
'foo',
[ qw/foo bar baz/ ],
{
'id' => '123456',
'name' => 'foo',
'date' => '2010-09-26',
},
'bar',
123456,
];
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 0;
benchmark();
sub benchmark {
cmpthese(timethese(-5, {
'data_dumper' => \&data_dumper,
'data_dump' => \&data_dump,
'data_messagepack' => \&data_messagepack,
'json_xs' => \&json_xs,
}));
}
sub data_dumper {
Data::Dumper::Dumper($data);
}
sub data_dump {
scalar Data::Dump::dump($data);
}
sub data_messagepack {
Data::MessagePack->pack($data);
}
sub json_xs {
JSON::XS::encode_json($data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment