Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
sorry if I wasn't being clear enough...

>First of all, you're talking about a time-difference, but there's no context. The difference between 0.01 and 1.01 seconds is far more interesting than the difference between 15h36m55s and 15h36m56s.

I have a very large perl script (on the order of 10K lines of code). This is something that takes about 1-1/2 minutes overall to execute. does this help with the context?

I was looking more closely at some of the execution paths for opportunities of optimization and was wondering what benefit there would be to order the options in some big if...elsif blocks more carefully ordered and thought that it might be so I did some experiments

BUT if a 1M compares takes <1sec as it does with my first test script, it's probably not as significant as I thought, but 5 seconds with the second scrpipt begins to get my attention.

>Second, your first talk about a difference of 3/4 of a second, then of a difference of 5. There's quite a difference in differences.

That's my point but I guess I didn't phrase the question properly, so let me try again.

In the first case what I'm trying to say is that to run that block of the 10 if...elsif... statements 1M times, takes about 3/4 of a second, the difference being that between the time it takes to execute them vs not-execute them.

However, when that identical block of code is run in the second script it takes over 7 times longer. THAT is my question - why?

>Third, without the return, you're doing 10 comparisons in an otherwise almost empty sub (the first time the sub is called, memory needs to be allocated, but Perl doesn't throw it away, making that in any subsequent call to the sub, the assignment to $a is relatively cheap), so I do expect there to be a difference.

Agreed and as I said above, that difference is the time takes to execute the 10 comparisons.

>Fourth, use the NYTProf profiler, and see how much time each statement takes.

I know, I was being lazy, but given the dramatic differences in the times I'd thing even my coarser level of analysis should be valid.

-mark


In reply to Re^2: Question about curious performance of if...elsif block by markseger
in thread Question about curious performance of if...elsif block by markseger

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 making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-19 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found