|
From: | Régis Houssin |
Subject: | [Dolibarr-dev] require_once vs class_exists |
Date: | Tue, 31 Jul 2012 18:48:13 +0200 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:14.0) Gecko/20120713 Thunderbird/14.0 |
Hi I did a little test performance between require_once and class_exists. we gain 50% performance gain using class_exists see the figures below (tested separately) class_exists condition will check only if the class is already included. A require_once will read the file, read file, create the hash, the hash compare to other hashes, and finally decide. $t1 = microtime(true); $nbloops = 3000; $file1 = 'compta/facture/class/facture.class.php'; $file2 = 'societe/class/societe.class.php'; $file3 = 'comm/propal/class/propal.class.php'; for ($i=0;$i<$nbloops;$i++){ if (! class_exists('Facture')) require $file1; if (! class_exists('Societe')) require $file2; if (! class_exists('Propal')) require $file3; } echo 'script executed in '.(microtime(true)-$t1).' s'; //script executed in 0.0548310279846 s for ($i=0;$i<$nbloops;$i++){ require_once $file1; require_once $file2; require_once $file3; } echo 'script executed in '.(microtime(true)-$t1).' s'; //script executed in 0.134128093719 s Cordialement, -- Régis Houssin --------------------------------------------------------- Cap-Networks Cidex 1130 34, route de Gigny 71240 MARNAY FRANCE VoIP: +33 1 83 62 40 03 GSM: +33 6 33 02 07 97 Web: http://www.cap-networks.com/ Email: address@hidden Dolibarr developer: address@hidden Web Portal: http://www.dolibarr.fr/ SaaS offers: http://www.dolibox.fr/ Shop: http://www.dolistore.com/ Development platform: https://doliforge.org/ --------------------------------------------------------- |
[Prev in Thread] | Current Thread | [Next in Thread] |