Categories
Photo A Day 2011

Project 365 Week 24

Finally caught up! The tugboat is a picture I didn’t even remember taking, but in retrospect is pretty cool. This seems to be a trend with me. The ones with least recall, or lowest expectations afterwards seem the best.

Categories
Photo A Day 2011

Project 365 Week 23

Some more vacation pictures plus some randoms. This was a big catch up week for me. I really like the cannon and beach.

Categories
Photo A Day 2011

Project 365 Week 22

More catch up. This is my week of vacation. Most of these pictures were just lightly touched up. I like this week.

Categories
Photo A Day 2011

Project 365 Week 21

I’m catching up from my backlog of posts here. This is the delayed Week 21. Not a bad week actually. Start of vacation photos as well.

Categories
Programming Web Development

PHP’s include_once() Is Insanely Expensive

I’ve always heard the include_once() and require_once() functions were computationally expensive in PHP, but I never knew how much. I tested the following out on my i7 2010 MacBook Pro using PHP 5.3.4 as shipped by Apple.

This first test uses include_once() to keep track of how often a file is included:

$includes = Array();
$file = ‘benchmarkinclude’;
 
for($i=0; $i < 1000000; $i++){
    include_once($file.‘.php’);
}

Took: 10.020140171051 sec

This second example uses include() and uses in_array() to keep track of if I loaded the include:

$includes = Array();
$file = ‘benchmarkinclude’;
 
for($i=0; $i < 1000000; $i++){
    if(!in_array($file, $includes)){
        include($file . ‘.php’);
        $includes[] = $file;
    }
}

Took: 0.27652382850647 sec

For both, the include had the following computation:

$x = 1 + 1;

Lesson learned: Avoid using _once if you can avoid it.

Update: That means something like this will theoretically be faster:

$rja_includes = Array();
function rja_include_once($file){
    global $rja_includes;
    if(!in_array($file, $rja_includes)){
        include($file);
        $rja_includes[] = $file;
    }
}