SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)

    include/require performance

    Profiling my scripts, the biggest drain on performance is the autoloader, specifically the require/include line.

    A current site includes 38 files.

    I did a quick test using include/require/require once/include once. Profiling just the autoload function and changing only the include/require line here's what I got just as a very basic test.

    require_once 124.75ms
    require 116.64ms
    include_once 120.56ms
    include 119.24ms


    All very close. Nothing really in it. However, 38 calls to include/require are using 70% of my script's CPU time so it's a hefty chunk of resources and easily the most resource intensive function I have.

    Now that still seemed a lot to me but perhaps it just a file I/O bottleneck. As a basic test, I tried:

    PHP Code:
    eval('?>' file_get_contents($file)); 
    instead of
    PHP Code:
    require $file

    The result... 24.29ms roughly five times faster. This is rather astonishing. obviously eval is bad™ but this proves that include/require are doing a hell of a lot more than simply loading the file. By using eval(file_get_contents()) I've improved my entire script performance by almost 100%.

    Any idea why include should be so comparatively slow?

    edit: the files being included are doing no real processing on include, they are all just class definitions.

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What version you running there Tom
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    5.3. However, I'm now wondering whether the profiler itself has something to do with it. I'm using Zend Studio 9 to profile the code. I wonder if the profiler has to modify the include function in some manner.

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,805
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    @TomB

    Have you tried using Pingdom.com to check the speed of your site? I find that the PHP optimisation makes very little difference and the biggest time gobbler is the waiting for the server to respond.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •