in reply to Re^2: On optimizing nested loops
in thread On optimizing nested loops
If @in is fairly long, then I'd certainly expect this:
@in = grep { $_->{$field} eq $value } @in;
To be measurably faster than:
@out = grep { $_->{$field} eq $value } @in; @in = @out;
Another optimization you could try is to note that each field you process cuts down the size of @in, so it makes sense to first process the fields that will cut it down the most. Filtering on gender eq "f" is probably going to cut out around 50% of @in, but filtering on surname eq "Davis" is likely to cut out around 99%.
Right now, you're iterating through keys %$where in no particular order - i.e. hash order. Sorting keys %$where to prioritize keys where the data exhibits a high degree of variation ought to speed many searches up significantly, and the only cost will be sorting what is presumably a fairly small list of hash keys.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: On optimizing nested loops
by FloydATC (Deacon) on Oct 22, 2014 at 20:21 UTC |