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.8 by root, Tue Apr 3 23:59:04 2007 UTC vs.
Revision 1.9 by root, Tue Apr 10 03:47:26 2007 UTC

5use JSON; 5use JSON;
6use JSON::DWIW; 6use JSON::DWIW;
7use JSON::PC; 7use JSON::PC;
8use JSON::XS qw(to_json from_json); 8use JSON::XS qw(to_json from_json);
9use JSON::Syck; 9use JSON::Syck;
10use Storable ();
10 11
11use Time::HiRes; 12use Time::HiRes;
12use List::Util; 13use List::Util;
13 14
14use utf8; 15use utf8;
20 21
21my $json; # the test string 22my $json; # the test string
22 23
23local $/; 24local $/;
24$json = <>; 25$json = <>;
26
27# fix syck-brokenised stuff
28$json = JSON::XS->new->ascii(1)->encode (JSON::Syck::Load $json);
25 29
26#srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]); 30#srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]);
27 31
28#if (1) { 32#if (1) {
29# use Storable; 33# use Storable;
41 "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'], 45 "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'],
42 "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'], 46 "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'],
43 "JSON::XS" => ['to_json $perl' , 'from_json $json'], 47 "JSON::XS" => ['to_json $perl' , 'from_json $json'],
44 "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'], 48 "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'],
45 "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'], 49 "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'],
50 "Storable" => ['Storable::nfreeze $perl', 'Storable::thaw $pst'],
46); 51);
47 52
48sub bench($) { 53sub bench($) {
49 my ($code) = @_; 54 my ($code) = @_;
50 55
51 my $perl = jsonToObj $json; 56 my $perl = jsonToObj $json;
57 my $pst = Storable::nfreeze $perl;
58
52 my $count = 20; 59 my $count = 2;
53 my $times = 25; 60 my $times = 25;
54 61
55 my $cent = eval "sub { " . (join ";", ($code) x $count) . "}"; 62 my $cent = eval "sub { " . (join ";", ($code) x $count) . "}";
56 $cent->(); 63 $cent->();
57 64

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines