Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Can someone please write a *working* JSON module

by Fletch (Chancellor)
on Oct 24, 2021 at 08:53 UTC ( #11137949=note: print w/replies, xml ) Need Help??


in reply to Can someone please write a *working* JSON module

eval makes JSON::XS even slower than JSON::PP

Erm . . . Citation needed.

#!/usr/bin/env perl use 5.032; use Benchmark qw( :all ); use JSON::PP (); use JSON::XS (); use Cpanel::JSON::XS (); my $good_data = q{{"a": 1, "b": 2, "c": 3}}; my $bad_data = q{{Invalid: JSON, IS: Invalid}}; my @lots_o_good = ($good_data) x 50; my @lots_o_bad = ($bad_data) x 50; cmpthese( 5_000, { pp_good_no_eval => sub { my $parsed; for my $line (@lots_o_good) { $parsed = JSON::PP::decode_json($line); } }, pp_good_eval => sub { my $parsed; for my $line (@lots_o_good) { $parsed = eval { JSON::PP::decode_json($line) }; } }, pp_bad => sub { my $parsed; for my $line (@lots_o_bad) { $parsed = eval { JSON::PP::decode_json($line) }; } }, xs_good => sub { my $parsed; for my $line (@lots_o_good) { $parsed = JSON::XS::decode_json($line); } }, xs_good_eval => sub { my $parsed; for my $line (@lots_o_good) { $parsed = eval { JSON::XS::decode_json($line) }; } }, xs_bad => sub { my $parsed; for my $line (@lots_o_bad) { $parsed = eval { JSON::XS::decode_json($line) }; } }, cpanel_good => sub { my $parsed; for my $line (@lots_o_good) { $parsed = Cpanel::JSON::XS::decode_json($line); } }, cpanel_good_eval => sub { my $parsed; for my $line (@lots_o_good) { $parsed = eval { Cpanel::JSON::XS::decode_json($line) +}; } }, cpanel_bad => sub { my $parsed; for my $line (@lots_o_bad) { $parsed = eval { Cpanel::JSON::XS::decode_json($line) +}; } }, } ); exit 0; __END__ Rate pp_bad pp_good_eval pp_good_no_eval xs_bad cp +anel_bad cpanel_good_eval xs_good_eval cpanel_good xs_good pp_bad 228/s -- -55% -56% -97% + -97% -99% -99% -99% -99% pp_good_eval 510/s 124% -- -1% -92% + -93% -98% -98% -99% -99% pp_good_no_eval 514/s 125% 1% -- -92% + -93% -98% -98% -99% -99% xs_bad 6757/s 2865% 1226% 1215% -- + -8% -80% -80% -82% -82% cpanel_bad 7353/s 3126% 1343% 1331% 9% + -- -78% -78% -81% -81% cpanel_good_eval 33333/s 14527% 6440% 6387% 393% + 353% -- -0% -13% -13% xs_good_eval 33333/s 14527% 6440% 6387% 393% + 353% 0% -- -13% -13% cpanel_good 38462/s 16777% 7446% 7385% 469% + 423% 15% 15% -- -0% xs_good 38462/s 16777% 7446% 7385% 469% + 423% 15% 15% 0% --

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137949]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-12-08 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (34 votes). Check out past polls.

    Notices?