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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines