in reply to RE: RE: Hash of hashes question
in thread Hash of hashes question
Being curious, I did a quick benchmark. However, its results defy logic (my (sort grep keys)[-1] is always faster than a O(1) "max()" algorithm!)
Since I am obviously missing something, would you be willing to post some benchmarking code showing the efficiency differences between "sort" and "max()" in this context?
Russ
P.S. Just for the sake of helping me find my silliness, here is what I was running. Changing the map to larger numbers (to make the source hash bigger) made no difference to the benchmark times.
The results were the same even without doing the assignment each time in b (only assign when we should, rather than each time through the loop). I left it this way for no apparent reason...#!/usr/bin/perl -w use strict; use Benchmark; my $now = 8; # we'll pretend it's between 8 and 9 PM my %url = ( monday => { @{[map(($_,1), (1..1000))]} } ); timethese(100000, { a => q{ $now = (sort grep {$_ <= $now} keys %{$url{'monday'}})[-1]; }, b => q{ $now = ($now < $_ && $_ < 8 ? $_ : $now) for keys %{$url{'monday'} +}; } });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE:(3) Hash of hashes question
by Aighearach (Initiate) on Jun 19, 2000 at 11:56 UTC | |
by Russ (Deacon) on Jun 19, 2000 at 23:10 UTC | |
by Aighearach (Initiate) on Jun 20, 2000 at 04:00 UTC | |
by Russ (Deacon) on Jun 20, 2000 at 05:28 UTC | |
by Aighearach (Initiate) on Jun 20, 2000 at 05:45 UTC |