]> Dogcows Code - chaz/p5-CGI-Ex/blob - samples/benchmark/bench_jsondump.pl
CGI::Ex 2.27
[chaz/p5-CGI-Ex] / samples / benchmark / bench_jsondump.pl
1 #!/usr/bin/perl -w
2
3 # As of JSON switch to 2.0 and new JSON interface
4 # Benchmark: running cejd, json, zejd for at least 2 CPU seconds...
5 # cejd: 3 wallclock secs ( 2.17 usr + 0.00 sys = 2.17 CPU) @ 7078.34/s (n=15360)
6 # json: 3 wallclock secs ( 2.24 usr + 0.00 sys = 2.24 CPU) @ 8723.21/s (n=19540)
7 # zejd: 3 wallclock secs ( 2.16 usr + 0.00 sys = 2.16 CPU) @ 7111.11/s (n=15360)
8 # Rate cejd zejd json
9 # cejd 7078/s -- -0% -19%
10 # zejd 7111/s 0% -- -18%
11 # json 8723/s 23% 23% --
12 #
13 # Benchmark: running cejd, json for at least 2 CPU seconds...
14 # cejd: 3 wallclock secs ( 2.08 usr + 0.00 sys = 2.08 CPU) @ 5800.48/s (n=12065)
15 # json: 2 wallclock secs ( 2.13 usr + 0.00 sys = 2.13 CPU) @ 7206.57/s (n=15350)
16 # Rate cejd json
17 # cejd 5800/s -- -20%
18 # json 7207/s 24% --
19 #
20 # Benchmark: running cejd, json for at least 2 CPU seconds...
21 # cejd: 2 wallclock secs ( 2.06 usr + 0.00 sys = 2.06 CPU) @ 30656.31/s (n=63152)
22 # json: 2 wallclock secs ( 2.08 usr + 0.00 sys = 2.08 CPU) @ 24666.35/s (n=51306)
23 # Rate json cejd
24 # json 24666/s -- -20%
25 # cejd 30656/s 24% --
26
27
28
29 use strict;
30
31 use Benchmark qw(cmpthese timethese);
32 use JSON;
33 use CGI::Ex::JSONDump;
34
35 my $json = JSON->new;
36 $json->canonical(1);
37 #$json->pretty;
38 my $cejd = CGI::Ex::JSONDump->new;
39
40
41 my $data = {
42 one => 'two',
43 three => [qw(a b c)],
44 four => 1,
45 five => '1.0',
46 six => undef,
47 };
48
49 print "JSON\n--------------------\n". $json->encode($data)."\n----------------------------\n";
50 print "CEJD\n--------------------\n". $cejd->dump($data) ."\n----------------------------\n";
51
52 cmpthese timethese(-2, {
53 json => sub { my $a = $json->encode($data) },
54 cejd => sub { my $a = $cejd->dump($data) },
55 zejd => sub { my $a = $cejd->dump($data) },
56 });
57
58 ###----------------------------------------------------------------###
59
60 $json = JSON->new;
61 $json->canonical(1);
62 $json->pretty;
63 $cejd = CGI::Ex::JSONDump->new({pretty => 1});
64
65 $data = {
66 one => 'two',
67 three => [qw(a b c)],
68 four => 1,
69 five => '1.0',
70 six => '12345678901234567890',
71 seven => undef,
72 };
73
74 print "JSON\n--------------------\n". $json->encode($data)."\n----------------------------\n";
75 print "CEJD\n--------------------\n". $cejd->dump($data) ."\n----------------------------\n";
76
77 cmpthese timethese(-2, {
78 json => sub { my $a = $json->encode($data) },
79 cejd => sub { my $a = $cejd->dump($data) },
80 });
81
82 ###----------------------------------------------------------------###
83
84 $json = JSON->new;
85 $json->canonical(1);
86 $json->pretty;
87 $cejd = CGI::Ex::JSONDump->new({pretty => 1, no_tag_splitting => 1});
88
89 $data = ["foo\n<script>\nThis is sort of \"odd\"\n</script>"];
90
91 print "JSON\n--------------------\n". $json->encode($data)."\n----------------------------\n";
92 print "CEJD\n--------------------\n". $cejd->dump($data) ."\n----------------------------\n";
93
94 cmpthese timethese(-2, {
95 json => sub { my $a = $json->encode($data) },
96 cejd => sub { my $a = $cejd->dump($data) },
97 });
This page took 0.043829 seconds and 4 git commands to generate.