I suppose my rationale behind using
join over string interpolation was that when working with directories, it is often advantageous to use an array instead of a string. This way you can resolve path components like '..' using
pop instead of a regex. The other idea was that each piece supplied to the join would represent a single path component, which could be validated using a quick
map for the extra paranoid. Of course, then $HOME would have to be split into something like @HOME.
Anyway,
Benchmark says:
Benchmark: timing 1000000 iterations of interpolator, joiner...
interpolator: 5 wallclock secs ( 5.13 usr + 0.00 sys = 5.13 CPU) @
+194931.77/s (n=1000000)
joiner: 4 wallclock secs ( 4.53 usr + 0.00 sys = 4.53 CPU) @ 22
+0750.55/s (n=1000000)
Rate interpolator joiner
interpolator 194932/s -- -12%
joiner 220751/s 13% --
From:
#!/usr/bin/perl
my ($the,$fastest,$donut,$youve,$ever,$seen) = qw [ the fastest donut
+you've ever seen ];
sub joiner
{
my $x = join ('/', $the,$fastest,$donut,$youve,$ever,$seen);
}
sub interpolator
{
my $x = "$the/$fastest/$donut/$youve/$ever/$seen";
}
use Benchmark qw [ cmpthese ];
cmpthese ( 1000000, {
joiner => \&joiner,
interpolator => \&interpolator,
}
);
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.