in reply to Re^14: Specializing Functions with Currying
in thread Specializing Functions with Currying
I prefer not to compare apples and oranges:
use Benchmark qw[ cmpthese ]; use List::Util qw[ first ]; our @array = 1 .. 100_000; cmpthese( -1, { func_10th => sub { first { length > 3 } @array; }, iter_10th => sub { for ( @array ) { return $_ if length > 3; } }, }); cmpthese( -1, { func_last => sub { first { length > 5 } @array; }, iter_last => sub { for ( @array ) { return $_ if length > 5; } }, }); __END__ Rate func_10th iter_10th func_10th 718/s -- -77% iter_10th 3139/s 337% -- Rate iter_last func_last iter_last 29.4/s -- -29% func_last 41.1/s 40% --
The results are similar if I run your code though.
Over here, first always wins given a sufficiently large number of iterations.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^16: Specializing Functions with Currying
by BrowserUk (Patriarch) on Aug 09, 2004 at 16:10 UTC | |
by Aristotle (Chancellor) on Aug 09, 2004 at 16:27 UTC |