in reply to Re^9: Specializing Functions with Currying
in thread Specializing Functions with Currying
I sometimes fall foul of that too. My most recent example was:
my $first = first{ length > 3 } @array; print $first;
Versus:
my $first; for ( @array ) { next unless length > 3; $first = $_; last; } print $first;
where, despite the compiled-loop nature of List::Util::first, the latter was considerably more efficient than the former if the required value was close to the front of the array.
Nearly twice as efficient with an array of 100,000 items and the thing I was looking for about a 10th of the way in.
Funnily enough, even if the item I was looking for was the last item in the array, the iterative approach was still quickest. I guess the penalty of entering and exiting the block scope is the cause?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^11: Specializing Functions with Currying
by Aristotle (Chancellor) on Aug 09, 2004 at 14:12 UTC | |
by adrianh (Chancellor) on Aug 09, 2004 at 14:18 UTC | |
by Aristotle (Chancellor) on Aug 09, 2004 at 14:34 UTC | |
by adrianh (Chancellor) on Aug 09, 2004 at 16:19 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2004 at 14:28 UTC | |
by Aristotle (Chancellor) on Aug 09, 2004 at 14:39 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2004 at 15:07 UTC | |
by Aristotle (Chancellor) on Aug 09, 2004 at 15:50 UTC | |
|