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
about.

An interesting talk on the subject:

        http://www.ccl4.org/~nick/P/Fast_Enough/

-- 
  Yuval Kogman <[EMAIL PROTECTED]>
http://nothingmuch.woobling.org  0xEBD27418

_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl

Reply via email to