Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: object oriented performance

by davebaker (Monk)
on Jul 17, 2005 at 01:42 UTC ( #475524=note: print w/replies, xml ) Need Help??

in reply to object oriented performance

From the Preface to Dr. Conway's book, Object Oriented Perl:
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 subrotine 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 [sic], 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."

But, he goes on to say, there are many compensating benefits, and he then lists them.

I just got the book today-- it looks terrific!

Published by Manning Publications Co. (, but I got mine through (click) for only $28.50 -- 34% off the cover price. I love that outfit.

Replies are listed 'Best First'.
Re^2: object oriented performance
by adrianh (Chancellor) on Jul 17, 2005 at 17:27 UTC
    A single method call is about 30 percent slower than a regular call to the same subroutine

    These days the performance hit for method calls is around 10-15%. I imagine that the caching of method lookups has got better over time.

    use strict; use warnings; use Benchmark qw( cmpthese ); { package Foo; sub new { bless {}, shift } sub self { $_[0] } } my $o = Foo->new; cmpthese(-1, { subroutine => sub { my $o = Foo::self( $o ) }, method => sub { my $o = $o->self }, }); __END__ # perl 5.8.7 on my box gives... Rate method subroutine method 579231/s -- -10% subroutine 643109/s 11% --

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://475524]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-09-24 09:08 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (273 votes). Check out past polls.