One Benchmark:
use strict;
use Benchmark;
for ( 1..5 ) # Do five tests.
{
$_ = int( rand(10_000) ) ** int( rand(3) + 2 );
print $_, "\n";
timethese( 1_000_000, {
'KM' => sub { 1 while s/^(-?\d+)(\d{3})/$1,$2/ },
'Merlyn' => sub { s/(\d)(?=(\d{3})+(\D|$))/$1\,/g }
});
print "\n", "- " x 39, "-\n";
}
Results:
82755409
Benchmark: timing 1000000 iterations of KM, Merlyn...
KM: 1 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 958772.77/s
(n=1000000)
Merlyn: 1 wallclock secs ( 0.49 usr + 0.00 sys = 0.49 CPU) @ 2036659.88/s
(n=1000000)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
293198635825936
Benchmark: timing 1000000 iterations of KM, Merlyn...
KM: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 949667.62/s
(n=1000000)
Merlyn: 0 wallclock secs ( 0.49 usr + 0.00 sys = 0.49 CPU) @ 2036659.88/s
(n=1000000)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
602425897921
Benchmark: timing 1000000 iterations of KM, Merlyn...
KM: 0 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 949667.62/s
(n=1000000)
Merlyn: 0 wallclock secs ( 0.47 usr + 0.00 sys = 0.47 CPU) @ 2123142.25/s
(n=1000000)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1.80935247108226e+015
Benchmark: timing 1000000 iterations of KM, Merlyn...
KM: 1 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 958772.77/s
(n=1000000)
Merlyn: 1 wallclock secs ( 0.46 usr + 0.00 sys = 0.46 CPU) @ 2169197.40/s
(n=1000000)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106294343553
Benchmark: timing 1000000 iterations of KM, Merlyn...
KM: 1 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 958772.77/s
(n=1000000)
Merlyn: 1 wallclock secs ( 0.48 usr + 0.00 sys = 0.48 CPU) @ 2083333.33/s
(n=1000000)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
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.
|