Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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. (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.


Comment on Re: object oriented performance
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-12-26 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (176 votes), past polls