Search performance test of php function

小云云
Release: 2023-03-21 15:20:01
Original
1542 people have browsed it

Used to observe the impact of Drupal modules on performance. The number of modules directly affects the number of hook function searches, and the function search speed affects performance. This article mainly shares with you the PHP function search performance test, hoping to help everyone.

Pay attention to the impact of the number of modules on overall performance, hooks are only one of them:

<?php
$php = "<?php\r\n";
for ($i = 0; $i < 10000; $i++) {
    $function_name = "f" . bin2hex(random_bytes(16));
    $php .= &#39;function &#39; . $function_name . &#39;($msg){echo $msg;}&#39; . "\r\n";
}
file_put_contents("yunke.php", $php);
include ("yunke.php");
$hooks = [];
for ($i = 0; $i < 10000; $i++) {
    $hooks[] = "f" . bin2hex(random_bytes(16));
}
$start_time = microtime(TRUE);
foreach ($hooks as $hook) {
    if (function_exists($hook)) {
        echo "$hook exists<br>";
    }
}
$end_time=microtime(TRUE);
echo "$start_time<br>$end_time<br>time:<br>";
echo $end_time - $start_time;
Copy after login


Test results:
Load 10,000 randomly named functions and find 10,000 The time consumption of a random function name is less than 2 milliseconds, and the impact is minimal. It can be considered that drupal's hook search does not affect performance

Test machine configuration:
cpu: Intel i5-7200U
Memory: 8G
system: win10

The above is the detailed content of Search performance test of php function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template