rfc:function_autoloading

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
rfc:function_autoloading [2013/08/30 11:39] – Update example code to show not needing a switch ircmaxellrfc:function_autoloading [2013/08/30 12:19] – add performance section ircmaxell
Line 1: Line 1:
 ====== PHP RFC: Function Autoloading ====== ====== PHP RFC: Function Autoloading ======
  
-  * Version: 0.1+  * Version: 0.2
   * Date: 2013-08-29   * Date: 2013-08-29
   * Author: Anthony Ferrara <ircmaxell@php.net>   * Author: Anthony Ferrara <ircmaxell@php.net>
Line 133: Line 133:
 ?> ?>
 </file> </file>
 +
 +==== Performance ====
 +
 +The following benchmarks are all run on a non-debug build compiled with //--disable-all --disable-cgi//. Note that the numbers provided are the average of the 3 fastest runs for a specific test (higher numbers are thrown out).
 +
 +=== Class Loading ===
 +
 +1000 classes were generated, each in a single file. The following test script was used to execute the following tests:
 +
 +<file php benchmark_autoloading.php>
 +<?php
 +spl_autoload_register(function($class) {
 +        require __DIR__ . '/files/' . $class . '.php';
 +});
 +
 +$start = microtime(true);
 +for ($i = 0; $i < 1000; $i++) {
 +        $class = 'test' . $i;
 +        new $class;
 +}
 +$end = microtime(true);
 +
 +echo "Completed in " . ($end - $start) . " seconds\n";
 +?>
 +</file>
 +
 +  * Master's //spl_autoload// loader: average 0.0225 seconds to load 1000 class files.
 +  * Proposed //php\autoload_register// loader: average 0.0219 seconds to load 1000 class files. (called via spl_autoload_register)
 +
 +Therefore, there is no performance regression when autoloading classes (in fact, it is slightly improved, since one additional //zend_function_call// call is removed).
 +
 +=== Functions ===
 +
 +1000 functions were generated and placed in a single file. The following test script was used to test if there was any change to function call time for a defined function:
 +
 +<file php benchmark_functions.php>
 +<?php
 +require_once 'functions.php';
 +
 +$start = microtime(true);
 +for ($i = 0; $i < 1000; $i++) {
 +        $func = 'test' . $i;
 +        $func();
 +}
 +$end = microtime(true);
 +
 +echo "Completed in " . ($end - $start) . " seconds\n";
 +?>
 +</file>
 +
 +  * Master: average 0.000216 Seconds to call 1000 functions
 +  * Proposal: average 0.000218 Seconds to call 1000 functions
 +
 +Therefore, there is no performance regression to normal function calls (defined functions).
  
 ==== Userland Backwards Compatibility ==== ==== Userland Backwards Compatibility ====
Line 289: Line 343:
  
   * 2013-08-29 0.1 Initial Creation   * 2013-08-29 0.1 Initial Creation
 +  * 2013-08-30 0.2 Add performance section and basic benchmarks
rfc/function_autoloading.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1