use strict;
use warnings;
use Devel::Size qw(size);
my $str = '';
for (1 .. 1_000_000) {
$str .= "x" x 80;
}
print "ASCII string has @{[ length($str) ]} characters and consumes @{[ size($str) ]} bytes\n";
$str = '';
for (1 .. 1_000_000) {
$str .= "\N{U+1234}" x 80;
}
print "Unicode string has @{[ length($str) ]} characters and consumes @{[ size($str) ]} bytes\n";
####
ASCII string has 80000000 characters and consumes 89779352 bytes
Unicode string has 80000000 characters and consumes 273984424 bytes
##
##
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)) ]}";