function_exists vs. extension_loaded

Одно небольшое бесполезное исследование провел сегодня на работе по долгу службы. Код и результаты его выполнения ниже.

<?php

$functionExistsStart = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
    function_exists('this_function_doesnt_exist');
}
$functionExistsEnd = microtime(true);

$extenstionLoadedStart = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
    extension_loaded('this_extension_is_not_loaded');
}
$extenstionLoadedEnd = microtime(true);

echo 'function_exists ' .
    ($functionExistsEnd - $functionExistsStart) .
    PHP_EOL;

echo 'extension_loaded ' .
    ($extenstionLoadedEnd - $extenstionLoadedStart) .
    PHP_EOL;
function_exists 0.35822796821594
extension_loaded 0.40138292312622

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.