#!perl
use strict;
use warnings;
use 5.020;
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 .= $string;
return $s1x;
}
## Method number two - an alphabetic sort
sub test_normal {
my $string = shift;
my $s1x = $string;
return $s1x;
}
## We'll test each one, with simple labels
my $count = 1000000;
timethese (
$count,
{
'Method One' => sub{ test_concat($s1); },
'Method Two' => sub{ test_normal($s1); },
}
);
exit(0);
####
Benchmark: timing 1000000 iterations of Method One, Method Two...
Method One: 4 wallclock secs ( 4.13 usr + 0.00 sys = 4.13 CPU) @ 242424.24/s (n=1000000)
Method Two: 5 wallclock secs ( 4.39 usr + 0.00 sys = 4.39 CPU) @ 227738.56/s (n=1000000)
##
##
>perl -MO=Concise script-concat.pl
6 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 4 script-concat.pl:7) v:*,&,{,x*,x&,x$
,$,201328640 ->3
5 <2> concat[t2] vKS/2 ->6
3 <0> padsv[$s1:4,5] sRM/LVINTRO ->4
4 <$> const[PV "Peter geht nach Hause geht"] s ->5
script-concat.pl syntax OK
>perl -MO=Concise script-assign.pl
e-variable-instantiation.pl
6 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 4 script-assign.pl:7) v:*,&,{,x*,x&,x$
,$,201328640 ->3
5 <2> sassign vKS/2 ->6
3 <$> const[PV "Peter geht nach Hause geht"] s ->4
4 <0> padsv[$s1:4,5] sRM*/LVINTRO ->5
script-assign.pl syntax OK