<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">Article 5393 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:5393
Newsgroups: comp.lang.perl
From: timbo@ig.co.uk (Tim Bunce)
Path: feenix.metronet.com!news.ecn.bgu.edu!psuvax1!uwm.edu!math.ohio-state.edu!cs.utexas.edu!uunet!news!demon!ig.co.uk!timbo
Subject: Re: What's the difference?
References: &lt;MCAMPBEL.93Aug16140708@debussy.sbi.com&gt; &lt;1993Aug19.122152.7130@colorado.edu&gt; &lt;CC0vCM.BwE@ig.co.uk&gt; &lt;1993Aug25.135401.14146@colorado.edu&gt;
Organisation: Paul Ingram Group, Software Systems, +44 483 424424
Date: Thu, 26 Aug 1993 18:13:25 +0000
Message-ID: &lt;CCDp98.IB9@ig.co.uk&gt;
Sender: usenet@demon.co.uk
Lines: 74

From the keyboard of tchrist@cs.colorado.edu (Tom Christiansen):
&gt;From the keyboard of timbo@ig.co.uk (Tim Bunce):
&gt;:join:    52 cpu seconds 
&gt;:interp:  60 cpu seconds 
&gt;:concat:  95 cpu seconds 
&gt;:sprintf: 75 cpu seconds 
&gt;
&gt;Try it on Perl5.
&gt;
&gt;--tom
&gt;    Tom Christiansen      tchrist@cs.colorado.edu       303-444-3212

Ok, here it is...

Roy Johnson &lt;rjohnson@shell.com&gt; kindly pointed out that I wasn't quite fair
(in my original post) to interpolation and sprintf, as I made them print commas
when join and concat didn't have to.

So I've modified the tests slightly and rerun them for perl4 and perl5:


Interp:   $x = "$a::$b::$c::$d::$e\n"
Join:     $x = join('',$a,'::',$b,'::',$c,'::',$d,'::',$e,"\n")
Concat:   $x = $a.'::'.$b.'::'.$c.'::'.$d.'::'.$e."\n"
Sprintf:  $x = sprintf("%s::%s::%s::%s::%s\n", $a,$b,$c,$d,$e);

Results:  Perl4    Perl5a2

Interp:   54.52 =&gt; 72.38  cpu seconds 
Join:     60.27 =&gt; 67.32  cpu seconds 
Concat:  136.88 =&gt; 73.18  cpu seconds 
Sprintf:  68.58 =&gt; 77.60  cpu seconds 

Note that the Perl4 is a fully optimised binary whereas the Perl5 is the
stock out-of-the-box sparc binary built by Larry with no optimisation at all.
If anyone has rebuilt perl5 with optimisation I'd be VERY interested in their
own perl4 vs perl5 figures.


For the curious, here's the code I used:

#!/usr/local/bin/perl

($a,$b,$c,$d,$e) = ('1234567890') x 5;
$loop = 1000000;
print "\n";

&amp;trial("Interp", &lt;&lt;'END');
    $x="$a::$b::$c::$d::$e\n"
END

&amp;trial("Join", &lt;&lt;'END');
    $x=join('',$a,'::',$b,'::',$c,'::',$d,'::',$e,"\n")
END

&amp;trial("Concat", &lt;&lt;'END');
    $x=$a.'::'.$b.'::'.$c.'::'.$d.'::'.$e."\n"
END

&amp;trial("Sprintf", &lt;&lt;'END');
    $x=sprintf("%s::%s::%s::%s::%s\n", $a,$b,$c,$d,$e);
END


sub trial{
    local($title, $code) = @_;
    eval join('','($u1,$s1)=times; $i=0;',
                 'while($i++ &lt; $loop){', $code, '};',
                 '($u2,$s2)=times');
    printf("$title: %.2f cpu seconds $@\n\n", ($u2+$s2)-($u1+$s1));
}

Regards,
Tim Bunce.


</pre></body></html>