Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Trying to understand Perl Objects

by targetsmart (Curate)
on Apr 05, 2009 at 01:01 UTC ( [id://755495]=note: print w/replies, xml ) Need Help??


in reply to Trying to understand Perl Objects

Some where I have read this 'perl code with object oriented-ness will run 40% slower that without oo', IMO perl tries to give you the OO facility by doing some workaround, but to the core it is not purely object oriented. I have read this 'Object oriented perl' book, it is good place to start knowing about perl OO. The OO in perl will help you in making reusable, scalable and maintainable code.
It is an appreciate-able thing that in Perl you can do both functional and object oriented programming.

Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.

Replies are listed 'Best First'.
Re^2: Trying to understand Perl Objects
by linuxer (Curate) on Apr 05, 2009 at 01:25 UTC

    Well, I remembered that, as I read your post, and did a little research.

    Conway mentions the speed thing in his book Object Oriented Perl (as you already mentioned).

    Luckily Manning Publications has the preface of that book online, so let's quote from there:

    Quoted from section "What object-oriented Perl isn't"

    Because Perl wasn't originally designed as an object-oriented language, object-oriented Perl isn't fast. Calling a method through an object is significantly slower than calling a regular Perl subroutine. Just how much slower is a matter of some debate, and depends on whether you measure entire software systems or just raw single-call invocation speed.

    A single method call is about 30 percent slower than a regular call to the same subroutine (depending on your hardware, your operating system, the phase of the moon, etc.) But though they're individually much slower, method calls are more powerful than regular subroutine calls, due to a feature known as polymorphism (see chapters 1 and 7). In a larger system, that redresses the speed imbalance in a little, but, in general, it's fair to say that an object-oriented implementation of a system in Perl will almost never be faster than the equivalent non-object-oriented implementation, and will usually be somewhere between 20 to 50 percent slower.

    ...

    The sad thing is that people get spooked by the numbers (20 to 50 percent slower!!!) and forget what that really means (...just as fast in six months time, when processor speeds have doubled).

    I never did some benchmarking on my own to determine how much slower OO Perl is on my machines. I trust Conway in this matter and try to enjoy the benefit of OO (as I'm learning OO) ;o)

Re^2: Trying to understand Perl Objects
by morgon (Priest) on Apr 05, 2009 at 01:22 UTC
    The problem is that calling a method via $object->method always means Perl has do a lookup of the sub to be invoked via the namespace (and possibly walking up the @ISA-chain).

    This of course is not free - but do you really want to write large applications in a purely imperative way? (functional by the way programming is something else - think Lisp or Haskell for that).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found