Posts Tagged ‘execution’

ini_alter vs ini_set in php

Tuesday, July 15th, 2008

Finally lets look at modifying the environment. I actually cheated here and just set the max execution time to 60 seconds a million times. I think the result is still valid though

ini_alter vs ini_set
ini_alter: 103.332370043 seconds
ini_set: 86.2883789539 seconds
Time saved: 17.0439910889 seconds; 19.7523598143%

As might be expected these functions are expensive when it comes to execution time. That 17 microsecond saving is massive as well making ini_set the superior choice.

PHP:PHPBench.com: Live PHP benchmarks, demystifying “best practices”

Monday, June 30th, 2008

When it comes to optimizing PHP for performance, there’s no end of resources available, and no end of conflicting opinions either. Everyone seems to have their own approach to writing “fast” PHP code; using single quotes, avoiding require_once() and using isset() before is_array() are some of the most common. But with reliable benchmarks thin on the ground, how do we know if any of these techniques - often touted as “performance best practices” - actually deliver benefits? Chris Vincent’s new PHP benchmark suite at PHPBench.com aims to “set the record straight” on PHP performance techniques, with a simple, comprehensive view of how various approaches actually stack up.

The benchmark suite covers all the usual bases, taking a simple task — like iterating over an array — and speed testing almost every possible way to achieve it. Most importantly, however, Chris takes raw numbers out of the spotlight and instead focuses on how the options compare with each other. Each test takes the fastest technique as the base value for execution time; all the other options are measured as percentages in relation to this. …

PHP:Write Clean Logic Statements

Monday, June 30th, 2008

Example 1: Unclean Conditional Logic

<?php
if($userLoggedIn) {
// Hundreds of lines of code
}else{
exit();
}
?>

The above statement seems straight forward, but it’s flawed for the reason that the developer is giving this conditional block too much responsibility. I know that might sound a little weird, but stay with me.

The type of conditional organization above makes for unnecessarily complex code to both interpret and maintain. A brace that’s paired with a control structure hundreds of lines above it won’t always be intuitive for developers to locate. I prefer the style of conditional logic in example 1.2, which inversely solves the previous example. Let’s take a look.

Example 2: Clean Conditional Logic

<?php

if(!$userLoggedIn) {
exit();

}

// Hundreds of lines of code

?>

This conditional statement is more concise and easier to understand. Instead of stating: “if my condition is met, perform hundreds of operations, else exit the script”, it’s saying “if my condition is not met, exit the script. Otherwise, I don’t care about what happens after that. I am only concerned with stopping execution”. So, by doing this, you’ve limited the operations that a given control structure has been tasked with, and that will help other developers quickly understand your code.

PHP:extend php script lifetime ( max_execution_time )

Monday, June 30th, 2008

ini_set( ‘max_execution_time’, 120 );