Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Yep, in my benchmark JSON::XS was faster than Storable too. Fun, I saw this module before several times, but always stopped reading doc just after "JavaScript" words thinking that this is something useless for me.

Update: In case somebody interested, here's the results of testing for some serializing engines. I've just got simple XML example from wikipedia, encoded it using different methods and benchmarked the parsers.

Here's the code:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; use XML::Simple; use JSON::XS; use YAML::Syck; use Data::Dumper; use Storable; use Fatal qw(open read close); my $xml; while(<DATA>){ $xml .= $_; } my $twig = XML::Twig->new(); my $href = XMLin($xml); my $dumper = Dumper($href); my $storable = Storable::freeze($href); my $json = encode_json($href); my $yaml = Dump($href); use Benchmark qw( cmpthese ); cmpthese -5, { 'XML::Simple' => sub { XMLin($xml) }, 'XML::Twig' => sub { $twig->parse($xml) }, 'JSON::XS' => sub { decode_json($json) }, 'YAML::Syck' => sub { Load($yaml) }, 'Storable' => sub { Storable::thaw($storable) }, 'Data::Dumper' => sub { eval($dumper) }, }; __DATA__ <recipe name="bread" prep_time="5 mins" cook_time="3 hours"> <title>Basic bread</title> <ingredient amount="8" unit="dL">Flour</ingredient> <ingredient amount="10" unit="grams">Yeast</ingredient> <ingredient amount="4" unit="dL" state="warm">Water</ingredient> <ingredient amount="1" unit="teaspoon">Salt</ingredient> <instructions> <step>Mix all ingredients together.</step> <step>Knead thoroughly.</step> <step>Cover with a cloth, and leave for one hour in warm room.</st +ep> <step>Knead again.</step> <step>Place in a bread baking tin.</step> <step>Cover with a cloth, and leave for one hour in warm room.</st +ep> <step>Bake in the oven at 180(degrees)C for 30 minutes.</step> </instructions> </recipe>

And here's the result:

Rate XML::Simple XML::Twig YAML::Syck Data::Dumper Sto +rable JSON::XS XML::Simple 422/s -- -24% -96% -97% + -99% -99% XML::Twig 556/s 32% -- -95% -96% + -99% -99% YAML::Syck 11622/s 2652% 1989% -- -11% + -81% -84% Data::Dumper 13039/s 2988% 2244% 12% -- + -79% -82% Storable 60964/s 14335% 10859% 425% 368% + -- -18% JSON::XS 74479/s 17535% 13289% 541% 471% + 22% --

In reply to Re^4: Creating Storable objects from the C by zwon
in thread Creating Storable objects from the C by zwon

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (4)
    As of 2019-07-22 07:38 GMT
    Find Nodes?
      Voting Booth?
      If you were the first to set foot on the Moon, what would be your epigram?

      Results (11 votes). Check out past polls.