in reply to performance issues with grepping large sorted arrays
Is there anyway I can make this run faster?
Don't use a data structure that requires a linear search. Use a hash instead, or, if that would get too large to fit into memory, use an indexed database, e.g. Berkeley DB (you might want to take a look at this recent thread, where a similar problem had been discussed).
If you really need to use an array, search it in a short-circuit way, i.e. don't use grep, but rather a for loop in combination with last, to exit the loop as soon as you've found a match:
my $found = 0; for (@A) { if ($_ eq $key) { $found = 1; last } } if ($found) { ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: performance issues with grepping large sorted arrays
by Trizor (Pilgrim) on Jul 23, 2007 at 23:34 UTC | |
by almut (Canon) on Jul 24, 2007 at 00:16 UTC | |
by gam3 (Curate) on Jul 24, 2007 at 14:25 UTC | |
by mr_mischief (Monsignor) on Jul 24, 2007 at 16:43 UTC | |
by almut (Canon) on Jul 24, 2007 at 17:35 UTC | |
by mr_mischief (Monsignor) on Jul 24, 2007 at 20:13 UTC |