in reply to Re: Speed Improvement
in thread Speed Improvement

Note that study() has been a no-op since 5.16.0

Dave.

Replies are listed 'Best First'.
Re^3: Speed Improvement
by GotToBTru (Prior) on Dec 02, 2014 at 15:20 UTC

    UPDATE: typo inflates the results here, study does not produce the improvement shown here. But it does do something, not nothing, so I'm pretty sure it's not a no-op.

    C:\perl>perl -v This is perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x +86-multi-thread-64int
    #!/usr/bin/perl use strict; use warnings; use 5.010; use Benchmark qw(cmpthese); my @messages = <DATA>; cmpthese(1000000, { 'mca_func' => sub { my $out = mca_substitute($_) foreach (@messages); }, 'toolic_func' => sub { my $out = toolic_substitute($_) foreach (@messages); }, 'study_func' => sub { my $out = study_substitute($_) for each (@messages); }, }); sub toolic_substitute { my $message = shift; $message =~ s/\{\\d(\d+)\}/sprintf "%0${1}d", int(rand(10**$1))/ge +; return $message; } sub study_substitute { my $message = shift; study $message; $message =~ s/\{\\d(\d+)\}/sprintf "%0${1}d", int(rand(10**$1))/ge +; return $message; } sub mca_substitute { my $message = shift; $message =~ s/\{\\d(\d+)\}/myreplace($1)/ge; return $message; } sub myreplace { return '' unless $_[0]; my $string = ''; $string .= int(rand 10) for (1..$_[0]); return $string; } __DATA__ This is a message! {\d3} --- {\d2} Another {\d3} Message with {\d5} A {\d1} little {\d6} longer string {\d3}
    C:\perl>perl testpm.pl Rate mca_func toolic_func study_func mca_func 34744/s -- -32% -78% toolic_func 50795/s 46% -- -68% study_func 157505/s 353% 210% -- C:\perl>

    Not bad for a no-op.

    1 Peter 4:10

      I think you may be being fooled by an error:

      my $out = study_substitute($_) for each (@messages); #..................................^^^?^^^^

      FWIW: I don't see any improvement (actually a 2% drop) in the performance of the study version (using 5.10/win).


      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.

        I got the same results once I fixed the typo: yours and McA's algorithms performed slightly worse, toolic's only marginally better when study was added. So something happened, definitely not a no-op, but nothing useful either! With such short strings, I shouldn't be surprised.

        1 Peter 4:10

      I stop working now in the hope that my no-op will result in such a gain in performance... :-)

      Thank you for that addition.

      McA