#!/opt/gsperl-5.8.6_1/bin/perl use strict; use Benchmark; my ($start,$end,$diff); my @data = (1..20000000); # start timer $start = new Benchmark; my %dataseen; my @arr; foreach my $x (@data) { push @arr, ($x+2); } # end timer $end = new Benchmark; # calculate difference my $diff = timediff($end, $start); # report print "Time taken by foreach loop was ", timestr($diff, 'all'), " seconds\n"; my $start1 = new Benchmark; my @arr1; @arr1 = map { push @arr1, ($_+ 2) } @data; # end timer my $end1 = new Benchmark; # calculate difference my $diff1 = timediff($end1, $start1); # report print "Time taken by map block was ", timestr($diff1, 'all'), " seconds\n";