Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Object Oriented Perfomance

by Rhandom (Curate)
on Apr 23, 2001 at 17:57 UTC ( [id://74714]=note: print w/replies, xml ) Need Help??


in reply to Object Oriented Perfomance

Use the Benchmark module. It will let you know relative speeds.

From what I've tested, method calls are around 20% slower. So, the question for your stuff is, do you need inheritance. If you do, then that answers it easily. Are your calls (to either function or method) in a tight loop (are there many iterations). If not, then again, the OOP might not be that bad (if it only takes one method call to get the whole thing rolling and you don't use the method calls after that, then by all means use OOP).

Another thing to consider is that if you are not using inheritance you can do things like this.
my $obj = MyObj->new( 'blah' ); while( 1 ){ my @args = qw( 'blah' ); &MyObj::my_method( $obj, @args ); }
When inheritance is not involved $obj->my_method( @args ); is the same as &MyObj::my_method( $obj, @args );. The only difference is speed.

my @a=qw(random brilliant braindead); print $a[rand(@a)];

Replies are listed 'Best First'.
(tye)Re: Object Oriented Perfomance
by tye (Sage) on Apr 23, 2001 at 19:38 UTC
    So, the question for your stuff is, do you need inheritance.

    When deciding on whether to use OO, inheritance is never in my the calculations and performance rarely is. In Perl at least, the main reason to use OO is that you need more than one "object", that is, a collection of data that you define some operations on. If you need more than one collection of data and more than one operation (especially if the number of operations is large or likely to grow), then OO is a good choice.

    You can do inheritance via Exporter.pm, using closures, or AUTOLOAD (to name a few), with or without the ability to create objects.

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found