Benchmarking DOMDocument creation with PHP

Posted: September 19th, 2008 | Author: | Filed under: PHP | Tags: | 2 Comments »

Representing data as XML has several advantages, all of which are not in the scope of this post. We will test several ways of creating a DOMDocument instance with a simple XML document. We will not be discussing differences between DOMDocument or SimpleXML or any of the other ways available to build XML structures. This post is concerned with the building (no manipulation either) of a simple XML tree.

Read the rest of this entry »


Benchmarking call_user_func

Posted: September 19th, 2008 | Author: | Filed under: PHP | Tags: | Comments Off on Benchmarking call_user_func

Calling object methods can be done in several ways:

  1. $oObject->method($param);
  2. $sMethod = 'method'; $oObject->{$sMethod}($param);
  3. call_user_func(array($oObject, 'method'), $param);

(call_user_method() function has been deprecated as of PHP 4.1.0, c.f. php.net.)

Intuitively the first type method calling is the preferred way to go both in terms of perfromance and readability. However, for the sake of generality (freedom, scripting or just exploiting the possibilities php provides), one of the latter two could be preferred. A quick performance comparisson may show which to use.

Read the rest of this entry »