ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/eg/bench
(Generate patch)

Comparing JSON-XS/eg/bench (file contents):
Revision 1.10 by root, Wed Jun 6 14:52:49 2007 UTC vs.
Revision 1.18 by root, Wed Mar 19 04:08:22 2008 UTC

2 2
3# Usage: bench json-file 3# Usage: bench json-file
4 4
5# which modules to test (JSON usually excluded because its so slow) 5# which modules to test (JSON usually excluded because its so slow)
6my %tst = ( 6my %tst = (
7 "JSON" => ['objToJson $perl' , 'jsonToObj $json'], 7# "JSON" => ['JSON::objToJson $perl' , 'JSON::jsonToObj $json'],
8# "JSON::PP" => ['$pp->encode ($perl)' , '$pp->decode ($json)'],
8 "JSON::DWIW" => ['$dwiw->to_json ($perl)', '$dwiw->from_json ($json)'], 9 "JSON::DWIW" => ['$dwiw->to_json ($perl)' , '$dwiw->from_json ($json)'],
9 "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], 10# "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'],
10 "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'], 11 "JSON::Syck" => ['JSON::Syck::Dump $perl' , 'JSON::Syck::Load $json'],
11 "JSON::XS" => ['to_json $perl' , 'from_json $json'], 12 "JSON::XS" => ['encode_json $perl' , 'decode_json $json'],
12 "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], 13 "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'],
13 "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], 14 "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'],
14 "Storable" => ['Storable::nfreeze $perl', 'Storable::thaw $pst'], 15 "Storable" => ['Storable::nfreeze $perl' , 'Storable::thaw $pst'],
15); 16);
16 17
17use JSON; 18use JSON ();
18use JSON::DWIW; 19use JSON::DWIW;
19use JSON::PC; 20use JSON::PC;
21use JSON::PP ();
20use JSON::XS qw(to_json from_json); 22use JSON::XS qw(encode_json decode_json);
21use JSON::Syck; 23use JSON::Syck;
22use Storable (); 24use Storable ();
23 25
24use Time::HiRes; 26use Time::HiRes;
25use List::Util; 27use List::Util;
26 28
27use utf8; 29use utf8;
28 30
29my $dwiw = new JSON::DWIW; 31my $dwiw = new JSON::DWIW;
30my $pc = new JSON::PC; 32my $pc = new JSON::PC;
33my $pp = JSON::PP->new->max_depth (512);
31my $xs2 = JSON::XS->new->utf8->pretty->canonical; 34my $xs2 = JSON::XS->new->utf8->pretty->canonical;
32my $xs3 = JSON::XS->new->utf8->shrink; 35my $xs3 = JSON::XS->new->utf8->shrink;
33 36
34my $json; # the test string 37my $json; # the test string
35 38
36local $/; 39local $/;
37$json = <>; 40$json = <>;
38 41
39# fix syck-brokenised stuff 42# fix syck-brokenised stuff
40$json = JSON::XS->new->ascii(1)->encode (JSON::Syck::Load $json); 43#$json = JSON::XS->new->ascii(1)->encode (JSON::Syck::Load $json);
41 44
42#srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]); 45#srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]);
43 46
44#if (1) { 47#if (1) {
45# use Storable; 48# use Storable;
52#} 55#}
53 56
54sub bench($) { 57sub bench($) {
55 my ($code) = @_; 58 my ($code) = @_;
56 59
57 my $perl = jsonToObj $json; 60 my $perl = JSON::XS::decode_json $json;
58 my $pst = Storable::nfreeze $perl; 61 my $pst = Storable::nfreeze $perl;
59 62
60 my $count = 5; 63 my $count = 5;
61 my $times = 200; 64 my $times = 200;
62 65

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines