in reply to Re: need more efficient way to write this query script
in thread need more efficient way to write this query script

Eek! While I suspect that would be faster, it's also is likely to involve a huge amount of backtracking if you have many IDs. Further, if the IDs are similar, this will decrease the performance even more. A straight hash lookup is going to be faster.

Of course, showing people how to dynamically build regexes (even simple ones) is always a nice trick :)

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

  • Comment on Re: Re: need more efficient way to write this query script

Replies are listed 'Best First'.
Re: Re: Re: need more efficient way to write this query script
by dws (Chancellor) on Aug 16, 2002 at 04:58 UTC
    While I suspect that would be faster, it's also is likely to involve a huge amount of backtracking if you have many IDs.

    True, but the target strings shown are pretty small. I'd benchmark this one before making assumptions about where the cutoverpoint between using a regex and using a hash is. I suspect that for a small number of keys, the regex wins.


    Hm... the original post doesn't give us much guidance about the cardinality of the key file. Given that, I'd probably go with a hash after all.