#!perl use strict; use warnings; use Benchmark; my $s1 .= 'Peter geht nach Hause geht'; my $s2 = 'Peter nach Hause geht'; ## Method number one - a numeric sort sub test_concat { my $string = shift; my $s1x; for (1 .. 100000) { $s1x .= $string; undef $s1x; } return $s1x; } ## Method number two - an alphabetic sort sub test_normal { my $string = shift; my $s1x; for (1 .. 100000) { $s1x = $string; undef $s1x; } return $s1x; } ## We'll test each one, with simple labels my $count = 100; timethese ( $count, { 'Method One' => sub{ test_concat($s1); }, 'Method Two' => sub{ test_normal($s1); }, } ); exit(0); #### Benchmark: timing 100 iterations of Method One, Method Two... Method One: 4 wallclock secs ( 3.40 usr + 0.00 sys = 3.40 CPU) @ 29.40/s (n=100) Method Two: 3 wallclock secs ( 3.59 usr + 0.00 sys = 3.59 CPU) @ 27.87/s (n=100) #### Benchmark: timing 100 iterations of Method One, Method Two... Method One: 3 wallclock secs ( 3.37 usr + 0.00 sys = 3.37 CPU) @ 29.68/s (n=100) Method Two: 4 wallclock secs ( 3.49 usr + 0.00 sys = 3.49 CPU) @ 28.61/s (n=100) #### Benchmark: timing 100 iterations of Method One, Method Two... Method One: 4 wallclock secs ( 3.45 usr + 0.00 sys = 3.45 CPU) @ 29.00/s (n=100) Method Two: 3 wallclock secs ( 3.49 usr + 0.00 sys = 3.49 CPU) @ 28.62/s (n=100)