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)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

In reply to RE: regexp for adding commas to a number by Adam
in thread regexp for adding commas to a number by Kozz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.