performance - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

performance

SupergibbsSupergibbs Posts: 50Member
I am trying to optimize a script given to me, is there much (any?) performance increase with this
[code]
print "".$q->popup_menu(...)."";

over this

print "";
print $q->popup_menu(...);
print "";
[/code]

thanks, Supergibbs

Comments

  • JonathanJonathan Posts: 2,914Member
    : I am trying to optimize a script given to me, is there much (any?)
    : performance increase with this
    : [code]
    : print "".$q->popup_menu(...)."";
    :
    : over this
    :
    : print "";
    : print $q->popup_menu(...);
    : print "";
    : [/code]
    :
    I'm pretty sure they'd lead to different parse trees rather than compiling down to the same thing, so they aren't directly equivalent. That said, I doubt there's a great deal of difference between them in terms of performance. Unless the concatenate operator or the print operator got overloaded/overridden with something hideously slow, which almost never happens to be the case.

    Do you actually have a performance problem with the script?

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • SupergibbsSupergibbs Posts: 50Member
    The script was written by my predecessor to display grades for students. It opens and parses a CSV file and displays a particular row/field. Eventually I am going to convert this to use MySQL but in the mean time my boss wanted me to optimize the script because it was eating up the webserver when multiple people accessed it.

    It is fairly simple, it reads the first line to get the fields and generates a form. Then after a submit, it reads line by line until it finds the user id then returns the requested field. I concatenated the prints and added a 'last' in the while loop (that reads line by line) but that only helps when the user id is towards the top.

    Any other things I should look for?

    -Jesse

    : : I am trying to optimize a script given to me, is there much (any?)
    : : performance increase with this
    : : [code]
    : : print "".$q->popup_menu(...)."";
    : :
    : : over this
    : :
    : : print "";
    : : print $q->popup_menu(...);
    : : print "";
    : : [/code]
    : :
    : I'm pretty sure they'd lead to different parse trees rather than compiling down to the same thing, so they aren't directly equivalent. That said, I doubt there's a great deal of difference between them in terms of performance. Unless the concatenate operator or the print operator got overloaded/overridden with something hideously slow, which almost never happens to be the case.
    :
    : Do you actually have a performance problem with the script?
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

  • JonathanJonathan Posts: 2,914Member
    : The script was written by my predecessor to display grades for students. It opens and parses a CSV file and displays a particular row/field. Eventually I am going to convert this to use MySQL but in the mean time my boss wanted me to optimize the script because it was eating up the webserver when multiple people accessed it.
    :
    : It is fairly simple, it reads the first line to get the fields and generates a form. Then after a submit, it reads line by line until it finds the user id then returns the requested field. I concatenated the prints and added a 'last' in the while loop (that reads line by line) but that only helps when the user id is towards the top.
    :
    : Any other things I should look for?
    :
    How are you checking if the user ID is the correct one? If you're doing something like:-

    if ($line =~ /^$userid/)

    Then it may well be seeing a variable is being used and re-compile the regex every iteration of the loop. Add the o modifier so it knows only to compile it once. Also be careful to check you haven't got a code injection security hole if you do have something that looks like what I posted. ;-)

    Just how big is the file anyway?

    Guess you can always try to run the thing under mod_perl instead of as a CGI.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.