use strict; use Benchmark; my ($x,$i); my @f = ('a'..'zz'); my $f = \@f; sub first_one { for (@f) {$x++} } sub second_one { for (@$f) {$x++} } sub third_one { for ('a'..'zz') {$x++} } sub fourth_one { for ($i=0;$i<=$#f;$i++) {$x++} } timethese(10_000, { 'first' => \&first_one, 'second' => \&second_one, 'third' => \&third_one, 'fourth' => \&fourth_one, }); #### Benchmark: timing 10000 iterations of first, fourth, second, third... first: 6 wallclock secs ( 6.02 usr + 0.00 sys = 6.02 CPU) @ 1661.68/s (n=10000) fourth: 12 wallclock secs (11.98 usr + 0.00 sys = 11.98 CPU) @ 834.86/s (n=10000) second: 7 wallclock secs ( 6.00 usr + 0.00 sys = 6.00 CPU) @ 1667.22/s (n=10000) third: 9 wallclock secs ( 9.57 usr + 0.00 sys = 9.57 CPU) @ 1044.50/s (n=10000)