Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: third_party/JSON/JSON-2.59/eg/bench_encode.pl

Issue 15736030: Add JSON.pm to third_party (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix permissions and shebangs Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/JSON/JSON-2.59/eg/bench_decode.pl ('k') | third_party/JSON/JSON-2.59/lib/JSON.pm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Benchmark qw( cmpthese timethese );
6
7 our $VERSION = '1.00';
8
9 my $wanttime = $ARGV[1] || 5;
10
11 use JSON qw( -support_by_pp -no_export ); # for JSON::PP::Boolean inheritance
12 use JSON::PP ();
13 use JSON::XS ();
14 use utf8;
15
16 my $pp = JSON::PP->new->utf8;
17 my $xs = JSON::XS->new->utf8;
18
19 local $/;
20
21 my $json = <>;
22 my $perl = JSON::XS::decode_json $json;
23 my $result;
24
25
26 printf( "JSON::PP %s\n", JSON::PP->VERSION );
27 printf( "JSON::XS %s\n", JSON::XS->VERSION );
28
29
30 print "-----------------------------------\n";
31 print "->encode()\n";
32 print "-----------------------------------\n";
33
34 $result = timethese( -$wanttime,
35 {
36 'JSON::PP' => sub { $pp->encode( $perl ) },
37 'JSON::XS' => sub { $xs->encode( $perl ) },
38 },
39 'none'
40 );
41 cmpthese( $result );
42
43 print "-----------------------------------\n";
44 print "->pretty->canonical->encode()\n";
45 print "-----------------------------------\n";
46
47 $pp->pretty->canonical;
48 $xs->pretty->canonical;
49
50 $result = timethese( -$wanttime,
51 {
52 'JSON::PP' => sub { $pp->encode( $perl ) },
53 'JSON::XS' => sub { $xs->encode( $perl ) },
54 },
55 'none'
56 );
57 cmpthese( $result );
58
59 print "-----------------------------------\n";
60
61
62 __END__
63
64 =pod
65
66 =head1 SYNOPSYS
67
68 bench_encode.pl json-file
69 # or
70 bench_encode.pl json-file minimum-time
71
72 =head1 DESCRIPTION
73
74 L<JSON::PP> and L<JSON::XS> encoding benchmark.
75
76 =head1 AUTHOR
77
78 makamaka
79
80 =head1 LISENCE
81
82 This library is free software; you can redistribute it and/or modify it
83 under the same terms as Perl itself.
84
85 =cut
86
OLDNEW
« no previous file with comments | « third_party/JSON/JSON-2.59/eg/bench_decode.pl ('k') | third_party/JSON/JSON-2.59/lib/JSON.pm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698