Invenzzia » Resources / Articles / Efficient autoloaders for PHP / Benchmark

4. Benchmark

Is Open Power Autoloader really that fast? Let's take a look at a benchmark. We have an environment with 200 classes grouped into 10 libraries represented by top-level namespaces. It is a typical situation encountered in modern web applications. In addition to the framework code, we often use plenty of third party tools, and the application itself has also its own namespace. Each autoloader had to load these 200 classes and build their objects. The trial was repeated 20 times, and after throwing away the worst result, the average time was calculated. The autoloader configuration time was not a subject of the measurement.

Autoloader name Average time Comments
Manual loading 0.0907 s
OPL ClassMapLoader 0.1005 s
OPL GenericLoader 0.1218 s
Doctrine 2 Class Loader 0.1450 s A single instance can handle only one namespace - we have to register 10 autoloaders, not compatible with PSR-0
SplClassLoader 0.1649 s A single instance can handle only one namespace - we have to register 10 autoloaders.
Symfony 2 Universal Class Loader 0.1826 s Allows to set different paths for sub-namespaces
Zend Framework 1.11 Loader 0.2092 s Advanced configuration and feature set, based on include_path settings which can make the result even worse, if the namespace are in completely different locations.

SplClassLoader and Doctrine 2 Class Loader can actually be faster than OPL GenericLoader, but only if we have a single top-level namespace. Because every new namespace requires another autoloader object to be created, the complexity of the autoloading operation increases. It does not happen in OPL Generic Loader, where the processing time is independent from the number of namespaces we have registered.