#1
  1. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2003
    Location
    GB
    Posts
    553
    Rep Power
    16

    functions slowing code


    i wanted to start a thread discussing the effects of user-created functions on the speed that some code runs at.

    The reason why is that i previously wrote some code to grab some remote content and display it, which took on average a couple of seconds to complete using broadband.

    I did not create any functions in the original code, it just went 'from top to bottom'.

    I recently decided to split the original code into four functions, so i could modify it easily in the future. However this new code is alot slower, taking around 10 seconds to complete this.

    Why is this? Is it because each function gets passed five variables, and therefore taking longer to do this?

    I was going to start using classes for the new site, but when it takes this much longer for functions to work i may just stick to sloppy top-to-bottom coding

    anyone have any views on this or am i just speaking complete crap??
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2003
    Location
    GB
    Posts
    553
    Rep Power
    16
    thought as much
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    USA
    Posts
    477
    Rep Power
    59
    It might be that the code inside the functions are poorly written, and there might be some error in them. Can you post some example code?
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2003
    Location
    GB
    Posts
    553
    Rep Power
    16
    i cant do that as its private code sorry

    the code is more or less the same as the original, just split into 4 functions
  8. #5
  9. AZbb founder
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    London, UK
    Posts
    843
    Rep Power
    15
    If it takes longer, it is likely that you have a loop which runs and does not stop.

    Do you get any errors?

    - Create a test page
    - Put a timer on it
    - Copy ONE function to it
    - run it and check the time
    - copy the same code for that ONE function as stand alone code
    - run it and compare

    That should give you clues.

    If you are running script on local machine without opening socks or urls, even a complicated script should not take even 1 second.

    AS soon as I run a script and it takes longer than 1 second, I know I have made a mistake somewhere.

    Good luck
  10. #6
  11. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    37
    There is simply no way in hell splitting your code into well structured functions will make it two times slower. No if's, not but's. Case closed.

    >anyone have any views on this or am i just speaking complete crap??
    Bullseye.
    And you know I mean that.

IMN logo majestic logo threadwatch logo seochat tools logo