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% --
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |