2 C functions below differ in a single line marked with 3 stars. I thought that a modern decent compiler won't notice. I'm afraid I'm not qualified to analyse compiler flags differences. It's Win10, and 5.32 set-up long ago and portable 5.42 (PDL-edition) unpacked just now. (The code is about PWC-342-2, it's irrelevant and doesn't matter if it still returns valid answers after reduction to SSCCE). Have compiler optimisation settings been changed, in recent Strawberries, in what looks like wrong direction? (+ some more strange issues, but I'd better stay focused on this one)

use strict; use warnings; use feature 'say'; use Benchmark 'cmpthese'; use constant L => 1e5; my $str = '1' x L; substr $str, rand L, 1 , '0' for 1 .. L; use Inline C => << 'END_OF_C'; int test_c_3( SV* str ) { int i, tmp, acc, max; STRLEN len; char* buf = SvPVbyte( str, len ); len --; acc = 0; max = -2; for( i = 0; i < len; i ++ ) { acc += ( buf[ i ] == '1' ); // *** tmp = i - 2 * acc; if ( tmp > max ) max = tmp; } return max + acc + ( buf[ len ] == '1' ) + 1; } int test_c_4( SV* str ) { int i, tmp, acc, max; STRLEN len; char* buf = SvPVbyte( str, len ); len --; acc = 0; max = -2; for( i = 0; i < len; i ++ ) { if ( buf[ i ] == '1' ) acc ++; // *** tmp = i - 2 * acc; if ( tmp > max ) max = tmp; } return max + acc + ( buf[ len ] == '1' ) + 1; } END_OF_C say $^V; say 'String length: ', L; cmpthese -2, { c3 => sub { test_c_3( $str )}, c4 => sub { test_c_4( $str )}, }; __END__ v5.32.1 String length: 100000 Rate c4 c3 c4 8800/s -- -0% c3 8817/s 0% -- v5.42.0 String length: 100000 Rate c4 c3 c4 2511/s -- -71% c3 8755/s 249% --

In reply to 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.