in reply to Re: Selective Optimization
in thread Selective Optimization

I suspect that the slowness of the app in general is due to IO (and database connections), it does a little bit of both over the network. For what I'm trying to optimize, however, it does neither.

I totally hear you on needing to see the code to answer anything specifically about where the problem might be. I'm unfortunately not in a position where I can post it in its entirety. Thanks, though.

Replies are listed 'Best First'.
Re^3: Selective Optimization
by jrsimmon (Hermit) on Dec 18, 2007 at 21:33 UTC
    Can you at least explain a little more clearly what the subroutines are doing? "a couple called as command line arguments that simply print data to the screen and exit" doesn't tell me much. How long does it take to run? How much time do you want to trim?

    If what you need to do is speed up specific subroutines, have you looked for any code that can be pulled out of sub? Are you opening/creating/etc some resource that could be held open to remove that step?

    Optimization questions are pretty hard to deal with unless you have at least some idea of the problem.
      Surely. I don't think there's any problems in sharing the help menus:
      sub help { # print basic help menu and exit. print "vpimport\n"; print "version $VERSION\n"; print "Format vendor price files for import to InOrder.\n\n"; print "Usage: vpimport [--vendor <VENDOR>] [--pricefile <file>] " . "[--outfile <file>] [--pricesource <name>] [--live] " . "[--no-create] [--help].\n"; print "--vendor <VENDOR> The vendor code of the vendor to update +.\n"; print "--pricefile <file> The name of the vendor's price file.\n" +; print "--pricesource <name> The price source to add/update.\n"; print "--live Use InOrder_Live instead of " . "InOrder_Development\n"; print "--no-create Don't create new inventory/vendor items +.\n"; print "--help Print this help and exit.\n"; print "--version Print version and exit.\n"; exit(0); }
      sub version { #print version number and exit print "$VERSION\n"; exit(0); }
      These are called via command line options (I'm using Getopt::Long) in the following code:
      my $result = GetOptions ( "version" => \&version, # print version and exit. "help" => \&help, # print basic help and exit. "vendor=s" => \$vendor, # The vendor code to update for. "pricefile=s" => \$pFile, # The vendor price file we're reading. "pricesource=s" => \$pSource, # name of the new price list, "live" => \$useLive, # Are we using the live database? "no-create" => \$no_create, # Don't create new items. );
        So you're wanting to optimize subroutines that only print text to the screen, and nothing else? Are you sure you read Optimizing existing Perl code (in practise) (the thread you linked earlier)? (jeffa) Re: Optimizing existing Perl code (in practise) seems to be particularly applicable. The time you'll spend on this would almost certainly be better spent finding ways to make your code more maintainable, better commented, etc.

        That said...
        Perhaps you could combine all of your data to be printed into a single scalar...this could possibly improve your help sub a bit...since you would only be calling into print a single time...