in reply to Speed Improvement

Try this (updated to reflect the error toolic caught below)(Further updated to correct flaws reported by dualafn):

sub substitute{ my $s = shift; $s =~ s[\{\\d(\d+)\}][ substr int( 1e10 + rand 1e10 ), 1, $1 ]ge; return $s };; print substitute( $_ ) for 'A message {d3} of {d4}';; A message 425 of 3404 print substitute( $_ ) for 'A message {d3} of {d4}';; A message 860 of 3797 print substitute( $_ ) for 'A message {d3} of {d4}';; A message 453 of 2262 print substitute( $_ ) for 'A message {d3} of {d4}';; A message 761 of 5898 print substitute( $_ ) for 'A message {d3} of {d4}';; A message 321 of 4182 print substitute( $_ ) for 'A message {d3} of {d4}';; A message 924 of 5054
[14:37:57.99] C:\test>junk Rate nar_func mca_func toolic_func buk_func nar_func 2449/s -- -26% -66% -78% mca_func 3287/s 34% -- -55% -70% toolic_func 7231/s 195% 120% -- -35% buk_func 11125/s 354% 238% 54% --

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Speed Improvement
by toolic (Bishop) on Dec 01, 2014 at 20:44 UTC
    I think it needs a small change to match the \d, but yours is still fastest:
    # vv $message =~ s[\{\\d(\d+)\}][ substr int( rand 1e9 ), 0, $1 ]ge; Rate mca_func toolic_func buk_func mca_func 41051/s -- -36% -56% toolic_func 64558/s 57% -- -30% buk_func 92678/s 126% 44% --
      it needs a small change to match the \d,

      Ah yes. That does lessen the impact somewhat doesn't it ;)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: Speed Improvement (Updated!)
by duelafn (Parson) on Dec 02, 2014 at 14:06 UTC

    Though, OP should note that mca and toolic functions will always produce a string of exactly the requested digits (possibly zero padded). The buk function can (very rarely) produce replacements which are shorter than requested (does not zero-pad). Also, buk's function will favor replacements which start with a non-zero digit (isn't uniform).

    Good Day,
        Dean

      The buk function can (very rarely) produce replacements which are shorter than requested (does not zero-pad). Also, buk's function will favor replacements which start with a non-zero digit (isn't uniform).

      Good catches both.

      I believe that this version corrects both problems without unduly impacting its performance:

      sub substitute{ my $s = shift; $s =~ s[\{\\d(\d+)\}][ substr int( 1e10 + rand 1e10 ), 1, $1 ]ge; return $s }

      Examples:

      A message 031 of 9150 A message 963 of 0677 A message 477 of 1689 A message 565 of 7675 A message 074 of 6471 A message 235 of 6949 A message 724 of 6703 A message 445 of 6304 A message 991 of 3243 A message 100 of 8825 A message 395 of 2102 A message 406 of 2886 A message 534 of 7045 A message 225 of 8037 A message 443 of 5097 A message 539 of 7089 A message 090 of 7777 A message 208 of 9697 A message 432 of 5864 A message 668 of 7766 A message 913 of 0511 A message 718 of 7972 A message 834 of 8521 A message 064 of 1745

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      Science is about questioning the status quo. Questioning authority