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.2 by root, Fri Mar 23 10:47:05 2007 UTC vs.
Revision 1.6 by root, Sat Mar 24 22:55:16 2007 UTC

13 13
14use utf8; 14use utf8;
15 15
16my $dwiw = new JSON::DWIW; 16my $dwiw = new JSON::DWIW;
17my $pc = new JSON::PC; 17my $pc = new JSON::PC;
18my $xs = JSON::XS->new->pretty (1)->canonical (1); 18my $xs2 = JSON::XS->new->utf8->pretty->canonical;
19my $xs3 = JSON::XS->new->utf8->shrink;
19 20
20my $json; # the test string 21my $json; # the test string
21 22
22local $/; 23local $/;
23$json = <>; 24$json = <>;
25
26#srand 0; $json = JSON::XS->new->utf8(1)->ascii(0)->encode ([join "", map +(chr rand 255), 0..2047]);
24 27
25#if (1) { 28#if (1) {
26# use Storable; 29# use Storable;
27# open my $fh, "<:unix", "/opt/crossfire/share/cfserver/faces" or die "$!"; 30# open my $fh, "<:unix", "/opt/crossfire/share/cfserver/faces" or die "$!";
28# my $faces = Storable::thaw do { <$fh> }; 31# my $faces = Storable::thaw do { <$fh> };
31# print $fh2 $json; 34# print $fh2 $json;
32# warn length $json; 35# warn length $json;
33#} 36#}
34 37
35my %tst = ( 38my %tst = (
39 "JSON" => ['objToJson $perl' , 'jsonToObj $json'],
36 "JSON::DWIW" => ['$dwiw->to_json ($perl)', '$dwiw->from_json ($json)'], 40 "JSON::DWIW" => ['$dwiw->to_json ($perl)', '$dwiw->from_json ($json)'],
41 "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'],
37 "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'], 42 "JSON::Syck" => ['JSON::Syck::Dump $perl', 'JSON::Syck::Load $json'],
38 "JSON::PC" => ['$pc->convert ($perl)' , '$pc->parse ($json)'],
39 "JSON" => ['objToJson $perl' , 'jsonToObj $json'],
40 "JSON::XS" => ['to_json $perl' , 'from_json $json'], 43 "JSON::XS" => ['to_json $perl' , 'from_json $json'],
41 "JSON::XS/2" => ['$xs->encode ($perl)' , '$xs->decode ($json)'], 44 "JSON::XS/2" => ['$xs2->encode ($perl)' , '$xs2->decode ($json)'],
45 "JSON::XS/3" => ['$xs3->encode ($perl)' , '$xs3->decode ($json)'],
42); 46);
43 47
44sub bench($) { 48sub bench($) {
45 my ($code) = @_; 49 my ($code) = @_;
46 50
47 my $perl = jsonToObj $json; 51 my $perl = jsonToObj $json;
48 my $count = 10; 52 my $count = 20;
49 my $times = 15; 53 my $times = 25;
50 54
51 my $cent = eval "sub { " . (join ";", ($code) x $count) . "}"; 55 my $cent = eval "sub { " . (join ";", ($code) x $count) . "}";
52 $cent->(); 56 $cent->();
53 57
54 my @meas; 58 my @meas;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines