Skip to content

Instantly share code, notes, and snippets.

@jadeallenx
Created June 23, 2014 02:02
Show Gist options
  • Save jadeallenx/17dc08b635967c144176 to your computer and use it in GitHub Desktop.
Save jadeallenx/17dc08b635967c144176 to your computer and use it in GitHub Desktop.
Do some primitive benchmarking on JSON serialization.
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(:all);
use Data::Random::Structure;
use Data::Dumper;
use JSON::PP ();
use JSON::XS ();
my $g = Data::Random::Structure->new();
my $ref = $g->generate();
warn Dumper $ref;
my %tests = (
'PP' => sub {
JSON::PP->new->utf8->encode($ref);
},
'XS' => sub {
JSON::XS->new->utf8->encode($ref);
},
);
cmpthese(50000, \%tests);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment