Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

grep on keys of associative array s-l-o-w. Why?

312 views
Skip to first unread message

Dominic Dunlop

unread,
Sep 17, 1992, 1:07:06 PM9/17/92
to
Well, here I am with perl 4.0 PL 35 on a SPARCstation (SunOS 4.1.1,
Sun C 1.1), trying the following

@possibles = grep(/^$oupname/o, keys %bncname);

where %bncname has 1,045 elements. The idea is that, if $oupname is
not actually a key, it may be the prefix of a key. The longest key is
perhaps 24 characters wide; $bnckey is six characters wide. The
operation is terribly slow. Run time goes up from 8 seconds to 40
seconds (two minutes without the o option on the pattern) when the
line is not commented out -- and I'm only hitting the statement about
40 times. Can someone tell me what (if anything) I'm doing wrong?

Thanks.
--
Dominic Dunlop

Larry Wall

unread,
Sep 21, 1992, 5:46:59 PM9/21/92
to
In article <1992Sep17.1...@onionsnatcorp.ox.ac.uk> dom...@onions.natcorp.ox.ac.uk (Dominic Dunlop) writes:
: Well, here I am with perl 4.0 PL 35 on a SPARCstation (SunOS 4.1.1,

Doing linear scans over an associative array is like trying to club someone
to death with a loaded Uzi.

What you wanna do is load all your key prefixes in as keys to an associative
array to begin with. If you don't want to replicate the values, load a
second array with the short keys mapped to the long keys.

Larry

0 new messages