Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: object oriented performance

by adrianh (Chancellor)
on Jul 17, 2005 at 17:27 UTC ( #475571=note: print w/ replies, xml ) Need Help??


in reply to Re: object oriented performance
in thread object oriented performance

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% --


Comment on Re^2: object oriented performance
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2015-07-02 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls