use strict; use warnings; use feature "say"; use Benchmark; use Devel::Size qw(size); my $t0 = Benchmark->new; my $total_bytes_chunked = 0; for (1 .. 1_000_000) { my $str = 'x' x 80; #$total_bytes_chunked += size($str); say STDERR $str; } my $t1 = Benchmark->new; my $str = ''; for (1 .. 1_000_000) { $str .= 'x' x 80 . "\n"; } my $total_bytes_lump = 0; #$total_bytes_lump = size($str); print STDERR $str; my $t2 = Benchmark->new; say "Printing in small chunks ($total_bytes_chunked bytes): @{[ timestr(timediff($t1, $t0)) ]}"; say "Printing one big chunk ($total_bytes_lump bytes): @{[ timestr(timediff($t2, $t1)) ]}";