use warnings; use strict; use JSON::XS; use Benchmark qw(cmpthese); my $coder = JSON::XS->new->ascii->pretty->allow_nonref; my $hashref = { one => 1, two => 2, three => 3, four => { nested => 'bird' } }; my $arrayref = [ 'one', 'two', 'three', 'four', 'five', 'six' ]; # cmpthese can be used both ways as well cmpthese( -1, { 'enc+dec hashref ' => sub { $coder->decode( $coder->encode( $hashref ) ) }, 'enc+dec arrayref ' => sub { $coder->decode( $coder->encode( $arrayref ) ) }, } ); __END__ #### [me@first ~]$ ./perl-json-test.pl Rate enc+dec hashref enc+dec arrayref enc+dec hashref 344063/s -- -22% enc+dec arrayref 438597/s 27% -- [me@second ~]$ ./perl-json-test.pl Rate enc+dec hashref enc+dec arrayref enc+dec hashref 153121/s -- -24% enc+dec arrayref 200972/s 31% --