Execution Speed Questions/Comparisons

Discussion in 'PHP' started by LazyD, Nov 4, 2007.

  1. #1
    So, I am building a web app that will need to be extremely fast, do finish a perticular task a single function will be called and the page will refresh calling that function and refreshing again, rinse repeat.

    Now, for the sake of execution time I have done certain things to help, like replaced preg searches with strpos and strstr so the regex engine doesnt have to start everytime the function has been called, ive also chosen to concentate strings instead of using sprintf, etc.

    My biggest concern now is whether have like 5 or 6 functions, totaling 1000 lines of code all in one file will show a significant slow down compared to every function being broken out into seperate files where only required code for that function is present.

    In the same realm, will there be any significant in using OOP techniques by making classes, extending classes, etc VS. good ol fashion stand alone functions.
     
    LazyD, Nov 4, 2007 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    It depends on how or when the functions need to be executed. There are costs in loading and parsing a large file, and there are also costs for opening a new file. So best will be to keep related functions in the same file, and others separate.

    In general, OO is slower than non-OO.


    NOTE: The above answers only consider about the code execution speed. You should consider the code readability and maintainability as well.
     
    phper, Nov 4, 2007 IP
  3. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yup phper is 100% correct :)

    There is a certain amount of overhead in creating objects that can slow down your script (albeit a fraction of a second)

    Is it necessary for your whole page to refresh? Can you just do an AJAX call and update the part that needs to be dynamic. This might cut down on your function calls.
     
    tonybogs, Nov 5, 2007 IP
  4. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    tamen, Nov 5, 2007 IP