http://qs321.pair.com?node_id=475524


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. (http://www.manning.com), but I got mine through bookpool.com (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% --