1- b() is faster than a() because the extra @ary. When benchmarking very fast operations, the overhead of creating variables is not negligible. Besides that, in a() you created a %hash on each iteration of the benchmark, in b() you are reusing %hash_b (forgotten the 'my'?)

2- Same as above... you are not doing the same thing. In c() a %hash is created on each iteration, in d() a global %hash_d is used. If a 'my' is added before %hash_d, then d() is faster than c()

3- Well... Storable is slower than split (from my experience, I can tell you that split is very very fast), so... why use Storable?

- Is less code, faster to write because that, and you don't need to test, debug or document it yourself.

- Is safer. For example, your example fails if the data contains '|'. And if you add escape sequences decoding, how much faster will still be split?

- Later you can change the serialized structure without updtaing the serializer and deserializer.

- Is not so slow, is no near half slow than split based code. The following sub is faster than a():

sub { my $hash_e = thaw($storable_serialized ); } # and then use $hash_e->{'2'}

Is easier, bah :-) Anyway, you probably will end spending more time fetching the data from the DB than deserializing it.

Hope this helps, José


In reply to Re: Benchmark on deserializing data by dont_you
in thread Benchmark on deserializing data by RL

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.