with length() 1000 L= 256000 t=0.510602 2000 L= 512000 t=1.544809 3000 L= 768000 t=2.558511 4000 L= 1024000 t=3.598220 5000 L= 1280000 t=4.622924 6000 L= 1536000 t=5.666133 7000 L= 1792000 t=6.634827 8000 L= 2048000 t=7.653030 9000 L= 2304000 t=8.687737 10000 L= 2560000 t=9.727445 11000 L= 2816000 t=10.728646 12000 L= 3072000 t=11.764352 13000 L= 3328000 t=12.804560 14000 L= 3584000 t=13.783257 15000 L= 3840000 t=14.836966 with a scalar 1000 L= 256000 t=0.003712 2000 L= 512000 t=0.003200 3000 L= 768000 t=0.003433 4000 L= 1024000 t=0.003232 5000 L= 1280000 t=0.003398 6000 L= 1536000 t=0.003669 7000 L= 1792000 t=0.004407 8000 L= 2048000 t=0.002218 9000 L= 2304000 t=0.004507 10000 L= 2560000 t=0.002192 11000 L= 2816000 t=0.005269 12000 L= 3072000 t=0.002203 13000 L= 3328000 t=0.006128 14000 L= 3584000 t=0.002311 15000 L= 3840000 t=0.002231 #### use strict; use warnings; use feature 'say'; use feature 'state'; use utf8; use Time::HiRes; $|++; my $chunk = '€' x 256; my $td = Time::HiRes::time; my $tf; my $l; say "with length()"; my $str = new LenTestA; for my $n (1..15_000){ state $count = 0; $str->add($chunk); $l = $str->len; $count++; if ($count % 1000 == 0){ $tf = Time::HiRes::time; say sprintf "%12d L=%10d t=%f", $n, $l, $tf-$td; $td = $tf; } } $td = Time::HiRes::time; say "\nwith a scalar"; $str = new LenTestB; for my $n (1..15_000){ state $count = 0; $str->add($chunk); $l = $str->len; $count++; if ($count % 1000 == 0){ $tf = Time::HiRes::time; say sprintf "%12d L=%10d t=%f", $n, $l, $tf-$td; $td = $tf; } } { package LenTestA; sub new { my $class = shift; my $self = ''; return bless \$self, $class; } sub add { my ($self, $data) = @_; $$self .= $data; } sub len { my $self = shift; return length $$self; } } { package LenTestB; my $len; sub new { my $class = shift; my $self = ''; return bless \$self, $class; } sub add { my ($self, $data) = @_; $$self .= $data; $len += length($data); } sub len { my $self = shift; return $len; } }