Wiggins has asked for the wisdom of the Perl Monks concerning the following question:
I am looking at a possible "time/space" trade-off problem. I am evaluating storing a set of data that is keyed by 3 attributes:
attr1 is a number in the range 200-35000The hash key is "attr1.attr2.attr3", The hash content is a ref to an anon array.
Could there be a significant performance improvement by maintaining a second hash of just 'attr1' to pre-determine if any keys start with attr1?
vsmy $arrayRef; if ( defined ?attr1Hash{$attr1}){ my $key ="attr1.attr2.attr3"; $arrayRef = $fullHash{$key}; } if ( defined $arrayRef){ ... }
UPDATE:my $arrayRef; my $key ="attr1.attr2.attr3"; $arrayRef = $fullHash{$key}; if ( defined $arrayRef){ ... }
I have a process that is watching (ala 'less') the system syslog file for pre-determined message keywords, which are reported across the net to a higher authority. Some of the tests done on a record may cause sub-shells to be spawned to determine system state.
But basicly pretty straight forward.
Generate a special event report if any unique process(pid), in a specified time period, creates more than 3 of the syslog messages. I have gone from statless scan to a time limited historic context.
The module I am working on holds the 'state'
$EventHash{$pid} = [ create_ts, last_upt, $ev_cnt];
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash space/ time tradeoff
by roboticus (Chancellor) on Dec 27, 2013 at 17:50 UTC | |
|
Re: Hash space/ time tradeoff
by Random_Walk (Prior) on Dec 27, 2013 at 16:59 UTC | |
|
Re: Hash space/ time tradeoff
by BrowserUk (Patriarch) on Dec 28, 2013 at 02:02 UTC | |
|
Re: Hash space/ time tradeoff
by GrandFather (Saint) on Dec 28, 2013 at 00:58 UTC | |
by educated_foo (Vicar) on Dec 28, 2013 at 01:45 UTC | |
by GrandFather (Saint) on Dec 28, 2013 at 04:09 UTC | |
by educated_foo (Vicar) on Dec 28, 2013 at 05:49 UTC | |
by GrandFather (Saint) on Dec 28, 2013 at 08:41 UTC | |
|
Re: Hash space/ time tradeoff
by Laurent_R (Canon) on Dec 27, 2013 at 19:03 UTC | |
|
Re: Hash space/ time tradeoff
by runrig (Abbot) on Dec 30, 2013 at 18:50 UTC | |
by BrowserUk (Patriarch) on Dec 30, 2013 at 19:04 UTC | |
by runrig (Abbot) on Dec 30, 2013 at 19:58 UTC | |
|
Re: Hash space/ time tradeoff
by locked_user sundialsvc4 (Abbot) on Dec 30, 2013 at 01:42 UTC |