use Benchmark qw(timethese); use strict; use warnings; my @array = (1 .. 100000); timethese(100, {granfather => \&grandfather, usual => \&usual}); sub grandfather { return 1 if grep {$_ == 100000} @array; } sub usual { for my $a (@array) { return 1 if ($a == 100000); } return 0; } #### Benchmark: timing 100 iterations of granfather, usual... granfather: 4 wallclock secs ( 3.58 usr + 0.00 sys = 3.58 CPU) @ 27.95/s (n=1 00) usual: 4 wallclock secs ( 4.13 usr + 0.00 sys = 4.13 CPU) @ 24.24/s (n=1 00) #### Benchmark: timing 100 iterations of granfather, usual... granfather: 3 wallclock secs ( 3.58 usr + 0.00 sys = 3.58 CPU) @ 27.95/s (n=1 00) usual: 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU) (warning: too few iterations for a reliable count) #### Benchmark: timing 100 iterations of granfather, usual... granfather: 4 wallclock secs ( 3.69 usr + 0.03 sys = 3.72 CPU) @ 26.89/s (n=1 00) usual: 2 wallclock secs ( 2.08 usr + 0.00 sys = 2.08 CPU) @ 48.12/s (n=1 00)