Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

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

Thank you for this. I've done this benchmark:

use strict; use Benchmark qw(:all); my $weapons_ref = { dagger => { cost => 8, damage => 4, armor => 0 }, shortsword => { cost => 10, damage => 5, armor => 0 }, warhammer => { cost => 25, damage => 6, armor => 0 }, longsword => { cost => 40, damage => 7, armor => 0 }, greataxe => { cost => 74, damage => 8, armor => 0 }, }; my @sum_fields = qw/cost damage armor/; my $count; cmpthese($count, { 'MapSub' => sub { my $sum_result; map { my $name = $_; map { $sum_result->{$_} += $weapons_ref->{$name}->{$_} } @sum_ +fields } keys %{ $weapons_ref }; }, 'ForSub' => sub { my $sum_result; foreach my $name (keys %{ $weapons_ref }) { foreach my $field (@sum_fields) { $sum_result->{$field} += $weapons_ref->{$name}->{$field}; } } }, });

And here's result:

Rate MapSub ForSub MapSub 197098/s -- -33% ForSub 294627/s 49% --

map is a bit slower, yes, but not critical. Anyway, thank you again, I will remember this if have to do code optimization.

In reply to Re^5: using ref to hash of hash effectively by alexander_lunev
in thread using ref to hash of hash effectively by kalee

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2021-07-30 01:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found