Reply to comment

bench

Hello,
As you suggested, I did the following comparison of the different ways to concatenate strings : concatenate 1 character x 1 million times.

#!/usr/bin/perl
#
sub DateHMS
{
# in : nothing
# out : date format: 10:26:42
$DH=`date '+%H:%M:%S'`;
chomp($DH);
return $DH;
}

$max=1000000;
$str="1";
$datehms=DateHMS();
print "dot: start = ".$datehms;
for ($i=1; $i<=$max; $i++)
{ $str = $str . '1';
}
$str="1";
$datehms=DateHMS();
print "\nincluded : start = ".$datehms;
for ($i=1; $i<=$max; $i++)
{ $str = "${str}1";
}
$str="1";
$datehms=DateHMS();
print "\noperator : start = ".$datehms;
for ($i=1; $i<=$max; $i++)
{ $str .= '1';
}
$str="1";
$datehms=DateHMS();
print "\njoin : start = ".$datehms;
for ($i=1; $i<=$max; $i++)
{ $str = join "", $str, "1";
}
$datehms=DateHMS();
print "\nend = ".$datehms."\n";

I ran it onto a Fujitsu Primepower 450 (4 sparc64 cpu x 1.648 Mhz). The results are very similar but for one method :
dot: start = 11:06:31
included : start = 11:12:12
operator : start = 11:18:01
join : start = 11:18:02
end = 11:23:52

that means :
dot : 5 mn 41 s
included : 5 mn 49 s
join : 5 mn 49 s

and operator: less than 1 second !!!!!
I ran it with 10 000 000 times : 9 seconds.

What method will you choose then ?

I'm interested in results on others kinds of architectures.

Regards
Frangi

Reply

The content of this field is kept private and will not be shown publicly.