Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • 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.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-19 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found