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.


In reply to Re: Can someone please write a *working* JSON module by Fletch
in thread Can someone please write a *working* JSON module by cnd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.