[Israel.pm] count chars

Yuval Kogman nothingmuch at woobling.org
Mon Sep 3 05:40:33 PDT 2007

On Mon, Sep 03, 2007 at 05:05:12 -0700, Ephraim Dan wrote:

> Interesting that tr/// is so much faster than index() - I wonder why that is?

Because perl's speed is generally directly proportional to the
number of opcodes involved in the code more than anything else.

There are two looping structures in the code:

	c_tr will loop in C iwthin the tr/// operator

	c_index will loop in Perl using opcodes

To execute the opcode tree each is walking a graph of pointers,
finding c functions by pointers, and executing them, so cache
locality, fiddling the stack, etc account for a lot of overhead that
the C code in the tr operator's implementation doesn't have to worry

An interesting talk on the subject:


  Yuval Kogman <nothingmuch at woobling.org>
http://nothingmuch.woobling.org  0xEBD27418

More information about the Perl mailing list