Okay, here is the max() given in Mastering Algorithms with Perl (O'Reilly):

sub max { # Numbers. my $max = shift; foreach ( @_ ) { $max = $_ if $_ > $max } return $max; }

So, modifying that to fit into our existing benchmark/profiling code, it looks like:

foreach ( keys %{$url{'monday'}} ) { $now = $_ if $_ > $now }

And then, the score:

 grep

constant item2
numeric le (<=)1000
shift1
sort1
hash dereference2
hash element1
pushmark10
grep1
grep iterator1000
scalar variable2001
next statement6
list slice1
scalar assignment2
keys1
subroutine exit1
block1000
array dereference1
glob value5
private variable3
subroutine entry4
 if/then/else

constant item993
foreach loop entry1
shift1
foreach loop iterator1001
iteration finalizer1000
hash dereference2
hash element1
pushmark7
scalar variable4992
next statement1007
logical and (&&)2001
scalar assignment1001
conditional expression1000
keys1
subroutine exit1
loop exit1
array dereference1
glob value6
private variable3
subroutine entry4
numeric lt (<)1992
 book max()

constant item1
foreach loop entry1
shift1
foreach loop iterator1001
iteration finalizer1000
hash dereference2
numeric gt (>)1000
hash element1
pushmark7
scalar variable2292
next statement2006
logical and (&&)2001
scalar assignment147
keys1
subroutine exit1
loop exit1
array dereference1
glob value6
private variable3
subroutine entry4
Benchmark: timing 10000 iterations of bench_grep, bench_if_then, bench_max...
bench_grep: 115 wallclock secs (111.04 usr +  0.01 sys = 111.05 CPU) @ 90.05/s (n=10000)
bench_if_then: 73 wallclock secs (70.02 usr +  0.01 sys = 70.03 CPU) @ 142.80/s (n=10000)
 bench_max: 64 wallclock secs (62.72 usr +  0.01 sys = 62.73 CPU) @ 159.41/s (n=10000)

Well, we have some surprises here! grep comes in last, even though it has the least operations. As you can see, not all operations are equal... but the book technique is the big winner. Which tells me it was worth the $35US.

The results also show that Devel::OpProf is a useful tool, but only as an accessory to Benchmark. On it's own, it can be misleading.

Paris Sinclair    |    4a75737420416e6f74686572
pariss@efn.org    |    205065726c204861636b6572
I wear my Geek Code on my finger.

In reply to RE: RE:(5) Hash of hashes question by Aighearach
in thread Hash of hashes question by Ovid

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.