in reply to RE:(5) Hash of hashes question
in thread Hash of hashes question
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:
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE:(7) Hash of hashes question
by Russ (Deacon) on Jun 20, 2000 at 05:28 UTC | |
by Aighearach (Initiate) on Jun 20, 2000 at 05:45 UTC |