views:

46

answers:

2

I previously wrote some utilities in Perl, and I am now rewriting them in order to give some new/better features. However, things seem to be going much more slowly than in the original utilities, so I decided to run one with the NYTProf profiler. Great profiler btw, still trying to figure out all its useful features.

So anyway, it turns out that 93% of my program's time is being spent on calls to the GeneModel::CORE:match (opcode) subroutine, and I have no idea what this is. Most Google hits point to NYTProf profiles others have posted. I indeed wrote the GeneModel class/package, but I don't know what this subroutine is, why it was called so many times, or why it's taking so long. Any ideas?

+9  A: 

CORE:match is a call to a regular expression -- in this case, within your GeneModel package.

For example, if we profile this script, Devel::NYTProf reports 1000 calls to Foo::CORE:match.

use strict;
use warnings;

package Foo;
my $s = 'foo foo';
$s =~ /foo/ for 1 .. 1000;
FM
+5  A: 

Perl is compiled to opcodes. The match operator results in a match opcode.

> perl -MO=Terse -e'm//'
LISTOP (0x8c4b40) leave [1]
    OP (0x8c4070) enter
    COP (0x8c4780) nextstate
    PMOP (0x8c4260) match

This is not a subroutine, but merely represented that way as opcode profiling is a recent addition and the UI hasn't been overhauled yet to take that into account. In simple words, the profiler is telling you that most time is spent in the regex engine.

daxim