מעכשיו פוסטים חדשים מ-Usenet לא יופיעו ואי אפשר להירשם לתוכן מ-Usenet בקבוצות Google. התוכן שכבר פורסם עדיין יופיע.

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

313 צפיות
מעבר להודעה הראשונה שלא נקראה

Dominic Dunlop

לא נקראה,
17 בספט׳ 1992, 13:07:0617.9.1992
עד
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

לא נקראה,
21 בספט׳ 1992, 17:46:5921.9.1992
עד
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 הודעות חדשות