Your test strings don't have any '-' hyphens in them. =)
And you change assignment forms between the two subs which
honestly shouldn't have much effect but is still questionable
practice when benchmarking since you want the code identical
in nature except for the key point you are testing...
Also, since the $data is set in the sub it
will be reset every pass. As well, you can just set up the benchmark like this and avoid having perl eval a sub call
in a string:
timethese ( $count,
{
'Method One S' => sub {
my $data = 'foo-bar-baz';
$data =~ s/-/_/g;
}
'Method Two TR' => sub {
my $data = 'foo-bar-baz';
$data =~ tr/-/_/;
}
}
);
Not a big deal but it may save you some typing in the
future. Your way has the benefit of being easy to run the
subs once and test their output, tho...
BTW, I moronically goofed my test string too... =)
--
$you = new YOU;
honk() if $you->love(perl)
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.