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,
}
);