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% --
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|