in reply to Re^7: AI in the workplace (... in the Monastery)
in thread AI in the workplace

The performance drop in "ugly" compared to "ugly_cr" can be attributed to the fact that `$1` and `$2` are read-only and are re-evaluated each time they are used in a comparison. This means that every time you check `$1` or `$2`, Perl has to numify them again, which adds overhead. In contrast, "ugly_cr" assigns these values to lexicals, which are faster to access.

Perl does have to numify them again, but not for the reason given.

no warnings qw( void ); use Devel::Peek qw( Dump ); "a" =~ /(.)/s or die; 0+$1; # Fetch and numify Dump($1); my $x = $1; # Fetch Dump($1);
... FLAGS = (GMG,SMG,POK,pIOK,pNOK,pPOK) ... FLAGS = (GMG,SMG,POK,pPOK) ...

As you can see, $1 gets numified. But every time you read from it, it gets repopulated since it's a magic variable. This wipes the previous values.

In the context of analyzing the AI's answer, it's worth noting that I missed the repeated numification in my answer. I stopped too soon.

The "any_cr" method is slower than "any" because of the additional overhead of assigning values to lexicals before performing the checks.

That can't be true since ugly_cr is way faster than ugly. The actual culprit is the overhead from the addition of capturing.

In the context of analyzing the AI's answer, it's worth noting the response is self-contradicting. According to the AI, assigning to the lexicals makes the cr version faster by only doing numification once, but it makes the cr version slower because of the addition of an assignment.

Replies are listed 'Best First'.
Re^9: AI in the workplace (... in the Monastery)
by LanX (Saint) on Jul 28, 2025 at 20:20 UTC
    In the example I've shown, the IV slot is set after the first numification.

    In fact it doesn't look to me like repeated numification (or magic fetching) was happening.

    :~$ perl -MDevel::Peek -E'"42"=~/(\d+)/; say $1; Dump $1; $a=$1+1; Dum +p $1; say $1; Dump $1' 2>&1 |grep IV IV = 0 IV = 42 IV = 42 :~$

    Edit

    hm ... probably the IV values don't matter if the appropriate I flags aren't set.

    ~$ perl -MDevel::Peek -E'"42"=~/(\d+)/; say $1; Dump $1; $a=$1+1; Dump + $1; say $1; Dump $1' 2>&1 |grep FLAGS FLAGS = (GMG,SMG,POK,pPOK) FLAGS = (GMG,SMG,IOK,POK,pIOK,pPOK) FLAGS = (GMG,SMG,POK,pPOK)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Correct, you should be looking at the flags.