Skip to content

Instantly share code, notes, and snippets.

@ggl
Created May 20, 2014 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggl/c3a13929bde01508935c to your computer and use it in GitHub Desktop.
Save ggl/c3a13929bde01508935c to your computer and use it in GitHub Desktop.
Timing JSON modules
#!/usr/bin/env perl
use strict;
use warnings;
use Try::Tiny;
use Benchmark qw(cmpthese);
use JSON::XS ();
use Cpanel::JSON::XS ();
use JSON::Tiny;
use Mojo::JSON;
use JSON::PP ();
use JSON::DWIW ();
my $data = {
a => 1,
b => 'foo',
c => [1, 'bar'],
d => { a => 1, b => 'foo' },
e => undef,
};
cmpthese -2, {
cpjxs => sub {
my $j = Cpanel::JSON::XS->new();
my $jdata = $j->encode($data);
$j->decode($jdata);
},
jxs => sub {
my $j = JSON::XS->new();
my $jdata = $j->encode($data);
$j->decode($jdata);
},
jt => sub {
my $j = JSON::Tiny->new();
my $jdata = $j->encode($data);
$j->decode($jdata);
},
mj => sub {
my $j = Mojo::JSON->new();
my $jdata = $j->encode($data);
$j->decode($jdata);
},
jpp => sub {
my $j = JSON::PP->new();
my $jdata = $j->encode($data);
$j->decode($jdata);
},
jdwiw => sub {
my $j = JSON::DWIW->new();
my $jdata = $j->to_json($data);
$j->from_json($jdata);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment