How about this:

use strict; use warnings; use feature 'say'; use Benchmark 'cmpthese'; use constant L => 1e5; my @cases; my $str = '1' x L; push @cases, $str; substr $str, rand L, 1 , '0' for 1 .. L; push @cases, $str; push @cases, '01' x ( L / 2 ); say $^V; for my $s ( @cases ) { cmpthese -2, { count => sub { $s =~ tr/1// }, } } __END__ v5.32.1 Rate count count 21711/s -- Rate count count 21607/s -- Rate count count 21348/s -- v5.42.0 Rate count count 16271/s -- Rate count count 2422/s -- Rate count count 8136/s --

String composition affects as trivial operation as counting. Looks like someone not heeded the advice to "write like C3, not C4" and relied on compiler voodoo, when writing Perl itself, not silly solution for PWC. Though of course it may be something else rather than innocent "if" with its jumps. Maybe situation can't be shrugged off after all.


In reply to Re: Weird performance issue with Strawberries and Inline::C by Anonymous Monk
in thread Weird performance issue with Strawberries and Inline::C by Anonymous Monk

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.