Created
September 26, 2010 12:57
-
-
Save Craftworks/597906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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