Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Wierd dprofpp results.

by dreadpiratepeter (Priest)
on Apr 12, 2002 at 15:54 UTC ( #158615=perlquestion: print w/replies, xml ) Need Help??

dreadpiratepeter has asked for the wisdom of the Perl Monks concerning the following question:

I have been getting wierd results from dprofpp involving BEGIN blocks. I get an inordinately high number of call to BEGIN and I don't understand why. I have distilled the problem down to a simple example:

file 1 (
package T; use strict; sub foo { } 1;

file2 (
package U; use T; sub foo { T->foo; } 1;

file 3 (
#!/usr/local/bin/perl use strict; use U; U->foo() foreach (0..10000);

When I run with perl -d:DProf and then run it though dprofpp tmon.out I get the following results:

Total Elapsed Time = -0.04006 Seconds User+System Time = 0 Seconds Exclusive Times %Time ExclSec CumulS #Calls sec/call Csec/c Name 0.00 0.040 0.005 10002 0.0000 0.0000 U::BEGIN 0.00 0.010 -0.005 10001 0.0000 - T::foo 0.00 0.000 -0.000 2 0.0000 - main::BEGIN 0.00 0.000 -0.000 2 0.0000 - strict::import 0.00 0.000 -0.000 2 0.0000 - strict::bits 0.00 0.000 -0.000 1 0.0000 - T::BEGIN

It appears that I get a BEGIN call in U every time I call a method in T. That doesn't sound right. I also changed the example to use straight function calls instead of class methods and I get the same results. Can anyone familiar with the internals elighten this poor friar?

"I am Jack's utter lack of disbelief"

Replies are listed 'Best First'.
Re: Wierd dprofpp results.
by dug (Chaplain) on Apr 12, 2002 at 18:45 UTC
    DProf seems to be lying.

    If in you replace:
    use T;

    BEGIN { require T; warn "executing BEGIN\n"; }

    you will only see the warning once, and dprofpp will still show 10002 calls to U::BEGIN.

    from perldoc perlmod:

    use Module ();
    is exactly equivalent to
    BEGIN { require Module; }

    Now, that said, I can't tell you why it's lying :)


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://158615]
Approved by Albannach
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2022-05-20 18:07 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (75 votes). Check out past polls.