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 .= 'function ' . $function_name . '($msg){echo $msg;}' . "\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;
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!