#!/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; } #### $ pm_1171789_concat_files.pl Source file: -rw-r--r-- 1 ken staff 1000000000 8 Feb 2013 /Users/ken/local/dev/test_data/text_G_1 *** SLURP MODE *** Duration (file 1): 10.8527989387512 seconds Duration (file 2): 10.3008499145508 seconds Duration (file 3): 9.28949189186096 seconds Duration (file 4): 9.32191705703735 seconds Duration (file 5): 9.52065896987915 seconds Duration (file 6): 8.99451112747192 seconds Duration (file 7): 8.9400429725647 seconds Duration (file 8): 11.1913599967957 seconds Duration (file 9): 8.92997598648071 seconds Duration (file 10): 9.06094002723694 seconds Total Duration: 96.4215109348297 seconds Average Duration: 9.64215109348297 seconds Concat file: -rw-r--r-- 1 ken staff 10000000000 15 Sep 09:25 pm_1171789_concat_files.out *** RECORD MODE *** Duration (file 1): 8.15429711341858 seconds Duration (file 2): 8.53961801528931 seconds Duration (file 3): 8.15934777259827 seconds Duration (file 4): 9.53512001037598 seconds Duration (file 5): 11.1551628112793 seconds Duration (file 6): 12.2594971656799 seconds Duration (file 7): 10.3394339084625 seconds Duration (file 8): 10.799164056778 seconds Duration (file 9): 11.6248168945312 seconds Duration (file 10): 12.0355160236359 seconds Total Duration: 102.602620124817 seconds Average Duration: 10.2602620124817 seconds Concat file: -rw-r--r-- 1 ken staff 10000000000 15 Sep 09:27 pm_1171789_concat_files.out