Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^4: Creating Storable objects from the C

by zwon (Abbot)
on Dec 25, 2008 at 09:34 UTC ( #732563=note: print w/replies, xml ) Need Help??

in reply to Re^3: Creating Storable objects from the C
in thread Creating Storable objects from the C

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% --

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2020-08-07 08:51 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (43 votes). Check out past polls.