in reply to Weird performance issue with Strawberries and Inline::C
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Weird performance issue with Strawberries and Inline::C
by ikegami (Patriarch) on Oct 16, 2025 at 15:00 UTC |