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__