4 ms·
how much of a performance drop have you measured in real world? compare my @judges = (); for my $sport (@sports) { if (is_watersport $sport) {
by ta0967 11y ago
how much of a performance drop have you measured in real world? compare
my @judges = ();
for my $sport (@sports) {
if (is_watersport $sport) {
push @judges, get_judges $sport;
}
}
to
my @judges = map get_judges, grep is_watersport, @sports;
is it worth fretting over an added pass? how many sports are we dealing with anyway? and IME, nested loops induce errors in the form of accidental `O(N*M)`.
- jlarocco 11y agoYour example is a straw man. IRL, I've seen this crop up while processing database results and large datasets. On several occasions I've shaved up to several minutes off of execution times by replacing chained map, filter, and zip calls that were iterating through the data multiple times with more complicated expressions that only performed the iteration once. I've also written a graphics applications where converting several chained map/filters into a single pass made interacting with the application noticeably less laggy. I'm actually surprised so many people have challenged this as a potential pitfall. I didn't pull it out of the air or from trivial examples. I've seen it happen.