in reply to Benchmarking chop/substr/split

Well, I bet it would be possible to teach Perl to optimize substr($str,-1) (when not being assigned to and when the "-1" is a literal constant) into chop. But then, why? That is, would the bit of bloat (and the potential for introducing bugs) be worth allowing people to write chop long-hand without the performance penalty?

BTW, they are all close enough to the same speed that I don't think I'd ever worry about the speed difference. (:

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Benchmarking chop/substr/split
by larryl (Monk) on Mar 17, 2001 at 02:15 UTC

    True, it might not be worth the bloat for something not frequently used. I'm just in a fuss because I read that gnat wants to take chop() out of the core.  I like chopchop is my friend.  I don't want to have to type  $a = substr($_,-1); substr($_,-1) = '' when what I want is  $a = chop.

    Pout.

    Besides, it's at least twice as fast every place I've tested it. If you need to check a few thousand credit cards a day, it makes a noticeable difference.

      Yeah, I like chop too. FYI, you don't have to repeat the substr: $a= substr($_,-1,1,""); Though this doesn't work in older versions of Perl.

              - tye (but my friends call me "Tye")