#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); my $file='test.txt'; my $file_size=1*1024*1024; # 1MB my $iter=1000; my $data=''; { my $lines=int($file_size/81); print "create DATA ($lines lines and 81 chars per Line)\n"; for(1..$lines) { $data.=join('',map{chr(int(rand(94))+32)}(1..80)).$/; } my $diff=$file_size-($lines*81); while($diff>0) { $data.=chr(int(rand(95))+32); $diff--; } } print "set FileHandle\n"; open(my $gfh, '<', \$data) or die("DATA : $!\n"); print "Run Benchmark\n"; cmpthese($iter, { 'read_all' => sub{ # goto start seek($gfh,0,0); my @l=<$gfh>; }, 'read_push' => sub{ # goto start seek($gfh,0,0); my @l; while(<$gfh>) { push(@l,$_); } }, });