The article uses the chart to tell you about PHP isset () and empty () function execution time comparison and performance of good and bad, the need for friends can be detailed to see OH. Performance tests are debugged using the Benchmark_iterate class tool, focusing primarily on the isset () and empty () function execution times.
, the test environment
Operating system: Windows XP
PHP Versions: PHP version 5.2.11
Apache version: Apache 2.0 Handler
Second, the test method
Use Benchmark_iterate to test isset () and empty to execute 50 times and generate a chart if the variable exists and does not exist
Three, Isset () and empty () determine if the variable does not exist
1, test the code
| The code is as follows |
Copy Code |
Require_once "benchmark/iterate.php"; $bench = new Benchmark_iterate; function Check1 ($var) { Isset ($var); } function Check2 ($var) { !empty ($var); } $bench->run ("Check1", $var); $bench->run ("Check2", $var); $result = $bench->get (); |
Where the $var variable is not initialized and the variable does not exist, the execution performance of the two functions is as follows
2,isset () The case that the variable does not exist
Plot: Isset () The average execution time between 0.0010-0.0011 seconds is determined by the absence of the variable
3,empty () The case that the variable does not exist
Plot: Empty () The average execution time between 0.0010 and 0.0011 seconds is determined when the variable does not exist
Four, Isset () and empty () determine the existence of variables
, test the Code
| The code is as follows |
Copy Code |
Require_once "benchmark/iterate.php"; $bench = new Benchmark_iterate;
function Check1 ($var) { Isset ($var); } function Check2 ($var) { !empty ($var); } $var = true; $bench->run ("Check1", $var); $bench->run ("Check2", $var); $result = $bench->get (); |
Initializes the $var variable to true, judging the existence of the variable, and the execution performance of the two functions is as follows
2,isset () Judging the existence of variables
Plot: Isset () Determine the existence of a variable average execution time between 0.0010-0.0011 seconds 3,empty () to determine the existence of a variable diagram: Isset () Judging the existence of the variable average execution time between 0.0010-0.0011 seconds combined with the above test performance, it is known that the Isset () and empty () function execution time is basically the same, The average execution time of two functions is between 0.0010-0.0011 seconds, of course, which is related to the specific environment, and the performance of the two functions is the same from the current test environment.
http://www.bkjia.com/PHPjc/444717.html www.bkjia.com true http://www.bkjia.com/PHPjc/444717.html techarticle The article uses the chart to tell you about PHP isset () and empty () function execution time comparison and performance of good and bad, the need for friends can be detailed to see OH. Performance test using Benchmark_ ...