#!/usr/bin/env perl use strict; use warnings; use autodie qw{:all}; use Time::HiRes qw{time}; my $source_file = "$ENV{HOME}/local/dev/test_data/text_G_1"; my $concat_file = 'pm_1171789_concat_files.out'; my $files_to_concat = 10; print "Source file:\n"; system "ls -l $source_file"; { print "*** SLURP MODE ***\n"; my $t0 = time; my ($t1, $t2); open my $out_fh, '>', $concat_file; for my $file_number (1 .. $files_to_concat) { local $/; $t1 = time; open my $in_fh, '<', $source_file; print {$out_fh} <$in_fh>; $t2 = time; print "Duration (file $file_number): ", $t2 - $t1, " seconds\n"; } print 'Total Duration: ', $t2 - $t0, " seconds\n"; print 'Average Duration: ', ($t2 - $t0) / $files_to_concat, " seconds\n"; print "Concat file:\n"; system "ls -l $concat_file"; unlink $concat_file; } { print "*** RECORD MODE ***\n"; my $t0 = time; my ($t1, $t2); open my $out_fh, '>', $concat_file; for my $file_number (1 .. $files_to_concat) { $t1 = time; open my $in_fh, '<', $source_file; print {$out_fh} $_ while <$in_fh>; $t2 = time; print "Duration (file $file_number): ", $t2 - $t1, " seconds\n"; } print 'Total Duration: ', $t2 - $t0, " seconds\n"; print 'Average Duration: ', ($t2 - $t0) / $files_to_concat, " seconds\n"; print "Concat file:\n"; system "ls -l $concat_file"; unlink $concat_file; }