can't do it with Inline::C, can I?

Yes I can, no need in separate source file; here to prove my claims from parent node:

use strict; use warnings; use feature 'say'; use Benchmark 'cmpthese'; use Config; say "$^V / $Config{ archname } / $Config{ gccversion }"; my $L = 1e6; my $str = '1' x $L; BEGIN { our $c = << 'END_OF_C'; int %s( SV* str ) { STRLEN len; char* buf = SvPVbyte( str, len ); len --; int acc = 0; int cum = 0; int max = -1; for( int i = 0; i < len; i ++ ) { int one = buf[ i ] - '0'; acc += one; cum += one ? -1 : 1; if ( cum > max ) max = cum; } return acc + max + ( buf[ len ] == '1' ); } END_OF_C } use Inline C => ' #pragma GCC target( "avx2" ) #pragma GCC optimize( "O3" ) ' . sprintf our $c, 'mscore_optimised'; use Inline C => sprintf our $c, 'mscore_default'; my %tests = ( default => sub { mscore_default( $str )}, optimised => sub { mscore_optimised( $str )}, ); say 'uniform string:'; cmpthese -1, \%tests; substr $str, rand $L, 1 , '0' for 1 .. $L; say 'random string:'; cmpthese -1, \%tests; __END__ v5.42.0 / MSWin32-x64-multi-thread / 13.2.0 uniform string: Rate default optimised default 897/s -- -19% optimised 1111/s 24% -- random string: Rate optimised default optimised 245/s -- -73% default 897/s 266% --

In reply to Re^5: 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.