EdsterTech has asked for the wisdom of the Perl Monks concerning the following question:
Note that I haven't been asked to look at performance (and a lot of the blame is on the large amount of data that it has to trawl through), but the Christmas period is usually a bit quiet and I think that a bit of fiddling might improve it, and am looking for confirmation (or warnings to the contrary!).
Firstly, the script initialises about 100 variables once in a while using the following style of declaration:
When I look at it, it looks wrong - I want to change them to:$totalamount = 0; $companyname = "";
or:$totalamount = undef; $companyname = undef;
Is this likely to improve performance, or does "pre-loading/maintaining" the variable type (integer/string) have some kind of use that I've been ignorant of for the past n years ?$totalamount = $companyname = undef;
Secondly, the script tests whether string variables are populated by using the length function, which seems a pointless way of slowing the script - e.g.
This is what I would have done:if ((length($companyname)>0) && ($anotherstring eq 'DOIT')) { ... }
Any comments appreciated.if (($companyname) && ($anotherstring eq 'DOIT')) { ... }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How does variable definition affect Perl performance ?
by ikegami (Patriarch) on Dec 04, 2009 at 23:09 UTC | |
Re: How does variable definition affect Perl performance ?
by gmargo (Hermit) on Dec 05, 2009 at 01:26 UTC | |
Re: How does variable definition affect Perl performance ?
by bv (Friar) on Dec 05, 2009 at 00:21 UTC | |
Re: How does variable definition affect Perl performance ?
by Joost (Canon) on Dec 05, 2009 at 04:14 UTC | |
Re: How does variable definition affect Perl performance ?
by cdarke (Prior) on Dec 05, 2009 at 16:34 UTC | |
by EdsterTech (Initiate) on Dec 05, 2009 at 21:07 UTC | |
Re: How does variable definition affect Perl performance ?
by wazoox (Prior) on Dec 05, 2009 at 11:05 UTC | |
by ikegami (Patriarch) on Dec 05, 2009 at 17:15 UTC |