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,
}
);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.