Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Update
This node was written partially because I didn't grok the point that chipmunk was making, but I believe it still serves as a useful clarification of the quote below. The important point here is that chipmunk is talking about the Benchmark _file_ and not package. See the follow ups for some interesting implications of this subtle difference. Also I have removed the later portion of the quoted sentence 'where the lexical @a and @b are not in scope ' because it appears I am discussing the lexical variables, whereas I am not. My apologies.
End Update

The eval of the code snippets occurs within Benchmark,

Actually, this isn't correct. Benchmark goes through some interesting (not necessarily completely correct either)contortions to execute code from the package it was called from, in this case main.

This can be seen from this snippet from Benchmark::runloop which is the primary timing routine in Benchmark. (BTW, i only know this cause ive been working on a OO version of Benchmark, coming Real Soon Now to the Code Catacombs :-)

# find package of caller so we can execute code there my($curpack) = caller(0); my($i, $pack)= 0; while (($pack) = caller(++$i)) { last if $pack ne $curpack; } my ($subcode, $subref); if (ref $c eq 'CODE') { $subcode = "sub { for (1 .. $n) { local \$_; package $pack; &\$c; +} }"; $subref = eval $subcode; } else { $subcode = "sub { for (1 .. $n) { local \$_; package $pack; $c;} } +"; $subref = _doeval($subcode); }
Oh and a note to andreychek I dont think that including print,warn statements in a benchmark (unless warn() is what you are benchmarking) is a good idea. The overhead of them executing probably drowns out the difference between the functions. Yves / DeMerphq
--
Have you registered your Name Space?

In reply to Re: Re: Re: Tribute to TMTOWTDI by demerphq
in thread Tribute to TMTOWTDI by s0ttle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found