[php] Function Efficiency

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by taekwondokid42, Apr 6, 2008.

  1. taekwondokid42

    taekwondokid42 New Member

    Messages:
    268
    Likes Received:
    0
    Trophy Points:
    0
    What would be more efficient:

    One script that is ~300 lines long, but if-else statments means that the server would only have to run ~100 of them

    Or

    One script that is ~50 lines long, and then re-directs the browser to another script that is ~100 lines long, and the server would have to run all of them.

    Or

    does it matter?
     
  2. cowctcat

    cowctcat New Member

    Messages:
    401
    Likes Received:
    0
    Trophy Points:
    0
    It really comes up to what connection speed do you think your visitors will have. I would say the safe bet is the first option.
     
  3. taekwondokid42

    taekwondokid42 New Member

    Messages:
    268
    Likes Received:
    0
    Trophy Points:
    0
    Ok, I'll go with that.

    I honestly have no idea which is more efficient, but my target is users with slower computers and connection speeds.
     
  4. konekt

    konekt New Member

    Messages:
    100
    Likes Received:
    0
    Trophy Points:
    0
    The first one comes of as much more efficient. Lines of code do not really denote efficiency, what those lines do does, however. Redirecting means that the user has to be re-served by the server, so if they have a slow connection it would be like loading twice as opposed to loading everything once.

    Loading time is not a linear relationship with code lines; when you request code you actually spend a little time speaking with the server. I believe you go back and forth eight times before the server ever sends anything, so imagine having to do that twice with a slow connection.
     

Share This Page