Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^13: The Most Essential Perl Development Tools Today (negative)

by petdance (Parson)
on Jan 13, 2013 at 15:41 UTC ( #1013112=note: print w/ replies, xml ) Need Help??


in reply to Re^12: The Most Essential Perl Development Tools Today (negative)
in thread The Most Essential Perl Development Tools Today

I suggest that if profiling has shown that you're calling a subroutine enough times that that the removal of a return makes any measurable difference in execution time, then the subroutine probably has almost no code in it at all, and the solution is to inline the tiny amount of code in the subroutine and remove the calling overhead entirely.

xoxo,
Andy


Comment on Re^13: The Most Essential Perl Development Tools Today (negative)
Download Code
Re^14: The Most Essential Perl Development Tools Today (negative)
by BrowserUk (Pope) on Jan 13, 2013 at 18:44 UTC
    then the subroutine probably has almost no code in it at all, and the solution is to inline the tiny amount of code in the subroutine and remove the calling overhead entirely.

    Sure, you could do that, but are you really going to allow all the callers of your objects to access their attributes directly rather than going through getters?

    Little bits add up! Here a 25% penalty just to satisfy two pointless P::C rules:

    #! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $o = bless { X=>1 }, 'main'; sub getX1{ my $self = shift; return $self->{X}; } sub getX2{ return $_[0]->{X}; } sub getX3{ $_[0]->{X}; } cmpthese -1, { A=> q[ my $x = $o->getX1(); ], B=> q[ my $x = $o->getX2(); ], C=> q[ my $x = $o->getX3(); ], }; __END__ C:\test>junk19 Rate A B C A 1441709/s -- -11% -20% B 1611352/s 12% -- -10% C 1797147/s 25% 12% --

    And that is just one level deep. Imagine (or test) the affect of calling a method that itself needs to call 2 or 3 getter() from one of its sub objects.

    The penalties, for what are purely cosmetic affectations, add up.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      #! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $o = bless { X=>1 }, 'main'; sub getX1{ my $self = shift; return $self->{X}; } sub getX2{ return $_[0]->{X}; } sub getX3{ $_[0]->{X}; } use Class::XSAccessor getters => { getX4 => 'X' }; cmpthese -1, { A=> q[ my $x = $o->getX1(); ], B=> q[ my $x = $o->getX2(); ], C=> q[ my $x = $o->getX3(); ], D=> q[ my $x = $o->getX4(); ], }; __END__ Rate A B C D A 251509/s -- -6% -12% -64% B 267957/s 7% -- -7% -62% C 286968/s 14% 7% -- -59% D 707950/s 181% 164% 147% --
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        Ignore that. I typoed (again) and fooled my self.

        Class::XSAccessor is very impressive. I'd like to see a version that worked with blessed arrays.

        But the primary point still stands. Getters are only one of many types of sub/method call that don't do very much, but you would not want to have to manually inline them everywhere they are used.

      I could be jumping to the wrong conclusion here, but you mentioned this speed boost before. Would this improve speed of web apps, using CGI::Application?

        Any performance gain is a nice side effect. The primary point is, not doing that which is not necessary, solely to satisfy some twisted notion of "correctness".

        Would this improve speed of web apps, using CGI::Application?

        Probably. Whether it would be enough that your clients would notice is doubtful, but if you are running the application on a server farm, you might be able to measure a reduction in your power usage that would be worth having.

        I can imagine that if Google found a way to reduce their electricity bill by even 5% by doing something -- or rather not doing something -- that required no other effort and had no other cost, they'd be all over it.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-09-18 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (111 votes), past polls