]> Dogcows Code - chaz/p5-CGI-Ex/blob - samples/benchmark/bench_jsondump.pl
38c1594dfaf2da28562bca734549ce0f461d97b9
[chaz/p5-CGI-Ex] / samples / benchmark / bench_jsondump.pl
1 #!/usr/bin/perl -w
2
3 # Benchmark: running cejd, json, zejd for at least 2 CPU seconds...
4 # cejd: 4 wallclock secs ( 2.18 usr + 0.00 sys = 2.18 CPU) @ 7045.87/s (n=15360)
5 # json: 3 wallclock secs ( 2.16 usr + 0.00 sys = 2.16 CPU) @ 6634.26/s (n=14330)
6 # zejd: 3 wallclock secs ( 2.16 usr + 0.00 sys = 2.16 CPU) @ 6634.26/s (n=14330)
7 # Rate zejd json cejd
8 # zejd 6634/s -- 0% -6%
9 # json 6634/s 0% -- -6%
10 # cejd 7046/s 6% 6% --
11 #
12 # Benchmark: running cejd, json for at least 2 CPU seconds...
13 # cejd: 3 wallclock secs ( 2.04 usr + 0.00 sys = 2.04 CPU) @ 5690.20/s (n=11608)
14 # json: 2 wallclock secs ( 2.06 usr + 0.00 sys = 2.06 CPU) @ 5291.75/s (n=10901)
15 # Rate json cejd
16 # json 5292/s -- -7%
17 # cejd 5690/s 8% --
18 #
19 # Benchmark: running cejd, json for at least 2 CPU seconds...
20 # cejd: 4 wallclock secs ( 2.21 usr + 0.00 sys = 2.21 CPU) @ 24320.81/s (n=53749)
21 # json: 3 wallclock secs ( 2.14 usr + 0.00 sys = 2.14 CPU) @ 10048.13/s (n=21503)
22 # Rate json cejd
23 # json 10048/s -- -59%
24 # cejd 24321/s 142% --
25
26 use strict;
27
28 use Benchmark qw(cmpthese timethese);
29 use JSON;
30 use CGI::Ex::JSONDump;
31
32 my $json = JSON->new(pretty => 0, keysort => 0);
33 my $cejd = CGI::Ex::JSONDump->new({pretty => 0, no_sort => 1});
34
35
36 my $data = {
37 one => 'two',
38 three => [qw(a b c)],
39 four => 1,
40 five => '1.0',
41 six => undef,
42 };
43
44 print "JSON\n--------------------\n". $json->objToJson($data)."\n----------------------------\n";
45 print "CEJD\n--------------------\n". $cejd->dump($data) ."\n----------------------------\n";
46
47 cmpthese timethese(-2, {
48 json => sub { my $a = $json->objToJson($data) },
49 cejd => sub { my $a = $cejd->dump($data) },
50 zejd => sub { my $a = $cejd->dump($data) },
51 });
52
53 ###----------------------------------------------------------------###
54
55 $json = JSON->new(pretty => 1, keysort => 1);
56 $cejd = CGI::Ex::JSONDump->new({pretty => 1});
57
58 $data = {
59 one => 'two',
60 three => [qw(a b c)],
61 four => 1,
62 five => '1.0',
63 six => '12345678901234567890',
64 seven => undef,
65 };
66
67 print "JSON\n--------------------\n". $json->objToJson($data)."\n----------------------------\n";
68 print "CEJD\n--------------------\n". $cejd->dump($data) ."\n----------------------------\n";
69
70 cmpthese timethese(-2, {
71 json => sub { my $a = $json->objToJson($data) },
72 cejd => sub { my $a = $cejd->dump($data) },
73 });
74
75 ###----------------------------------------------------------------###
76
77 $json = JSON->new(pretty => 1);
78 $cejd = CGI::Ex::JSONDump->new({pretty => 1});
79
80 $data = ["foo\n<script>\nThis is sort of \"odd\"\n</script>"];
81
82 print "JSON\n--------------------\n". $json->objToJson($data)."\n----------------------------\n";
83 print "CEJD\n--------------------\n". $cejd->dump($data) ."\n----------------------------\n";
84
85 cmpthese timethese(-2, {
86 json => sub { my $a = $json->objToJson($data) },
87 cejd => sub { my $a = $cejd->dump($data) },
88 });
This page took 0.03662 seconds and 3 git commands to generate.