# perl -MBenchmark -de0
DB<1> $a = "You now have a regular structure in memory, one which is very easy to deal with programmatically. To achieve your boss's first objective, which is to convert elements to attributes, you need to replace references to arrays, as shown in Listing 10."
DB<2> sub A () { return $a =~ m#^(.{,50})\s# ? $1 : substr $a,0,50; }
DB<3> sub B () { my $trim = substr $a,0,50; $trim =~ s#\s+\S*?$##; return $trim; }
DB<4> timethese (1_000_000,{ 'A' => \&A,'B' => \&B })
Benchmark: timing 1000000 iterations of A, B...
A: -6 wallclock secs (-5.79 usr + -0.04 sys = -5.83 CPU) @ -171526.59/s (n=1000000)
(warning: too few iterations for a reliable count)
B: 8 wallclock secs ( 7.74 usr + 0.05 sys = 7.79 CPU) @ 128369.70/s (n=1000000)
выделение памяти под $trim?, но и под return тоже выделяется...