Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: how to improve the performance of a perl program

by Tux (Monsignor)
on Aug 05, 2013 at 15:46 UTC ( #1047924=note: print w/ replies, xml ) Need Help??


in reply to how to improve the performance of a perl program

Do you consider Devel::NYTProf a viable option?


Enjoy, Have FUN! H.Merijn


Comment on Re: how to improve the performance of a perl program
Re^2: how to improve the performance of a perl program
by ghosh123 (Monk) on Aug 05, 2013 at 16:50 UTC

    Yes, I consider so. But I need an example to better understand it. Also can you please explain me how and why my no.1 point which is chain->of->accessors could be a problem ?
    Please also explain how can I use Class::Accessor ?
    Thanks.

      $chain->of->accessors often isn't a problem. However, if you've identified a bottleneck, you may need to consider what work is being done:

      • An inheritance lookup is done to decide which "->of" pertains to object $chain. This is a simple operation, but is more expensive than a direct subroutine call.
      • A subroutine call is executed. This involves pushing the call-frame onto the call-stack, and within the subroutine popping off items from the param stack. This is usually pretty quick, but considerably slower than looking up the value of a variable.
      • The accessor must do whatever work it must do. Perhaps it does no work other than returning a value. Maybe it's computing the 1-Billionth prime newly on each call. The cost depends entirely on how the accessor is implemented.
      • Next an object is returned so that ->accessors may be invoked on it. The return involves popping the current sub off the call-stack.
      • This process repeats for ->accessors.

      If that sounds like a lot of work, you're jumping to conclusions. If you put all that inside of a tight loop, inside of an algorithm that computes the Cartesian product of two human DNA sequences, yes... it's way too much work to be doing inside of a tight loop. If you're diving into that chain of accessors only every so often, then all the object lookup and call-stack work really fades into the background, and you maybe need to just consider how much work the individual accessors are doing internally. But until you've identified bottlenecks, it's a total waste of your time and the salary your employer pays you to just start making untested assumptions about performance, because you could be looking completely in the wrong places.

      As for your question about how to use Class::Accessor, before I explain how, let me ask you why you think you want to use it. Class::Accessor has about as much to do with code speed optimization as cruise controls have to do with drag racing. So if you do understand that Class::Accessor isn't a means to code speed optimization, and you still need it, then I suggest you read its documentation and ask a specific question about it, rather than asking "how to use" it when "how" is demonstrated right in its documentation.


      Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047924]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-12-29 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (186 votes), past polls