Home > Backend Development > PHP Tutorial > Comparison of execution time of PHP isset() and empty() functions_PHP tutorial

Comparison of execution time of PHP isset() and empty() functions_PHP tutorial

WBOY
Release: 2016-07-20 11:10:35
Original
827 people have browsed it

The article uses charts to tell you about the comparison of PHP isset() and empty() function execution times and the performance of the functions. Friends in need can take a detailed look. The performance test uses Benchmark_Iterate class tools for debugging, focusing mainly on the execution time of isset() and empty() functions.

, Test environment
Operating system: Window isset() and empty are executed 50 times and generate a chart when the variable exists and does not exist

3. isset() and empty() determine when the variable does not exist

1, test code

Illustration: empty () determines that the variable does not exist. The average execution time is between 0.0010-0.0011 seconds 4. isset() and empty() determines that the variable exists
The code is as follows
Copy code


require_once "Benchmark/Iterate.php"; $bench = new Benchmark_Iterate;
 代码如下 复制代码

require_once "Benchmark/Iterate.php";
$bench = new Benchmark_Iterate;
function check1($var){
    isset($var);
}
function check2($var){
    !empty($var);
}
$bench->run(50,"check1",$var);
//$bench->run(50,"check2",$var);
$result = $bench->get();

function check1($var){

isset($var);
}

function check2($var){

!empty($var);

}

$bench->run(50,"check1",$var); Comparison of execution time of PHP isset() and empty() functions_PHP tutorial//$bench-> run(50,"check2",$var);

$result = $bench->get();


Comparison of execution time of PHP isset() and empty() functions_PHP tutorial
where the $var variable is There is no initialization, and the execution performance of the two functions is as follows

2. isset() determines the case where the variable does not exist

 代码如下 复制代码

require_once "Benchmark/Iterate.php";
$bench = new Benchmark_Iterate;
 
function check1($var){
    isset($var);
}
function check2($var){
    !empty($var);
}
$var = true;
$bench->run(50,"check1",$var);
//$bench->run(50,"check2",$var);
$result = $bench->get();

Illustration: The average execution time of isset() when judging that the variable does not exist is between 0.0010-0.0011 seconds

3, and empty() when judging that the variable does not exist

Comparison of execution time of PHP isset() and empty() functions_PHP tutorialComparison of execution time of PHP isset() and empty() functions_PHP tutorial

, test 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(50,"check1",$var); //$bench->run(50,"check2",$var); $result = $bench->get();
Initialization If the $var variable is true, determine the existence of the variable. The execution performance of the two functions is as follows 2, isset() determines the existence of the variable Illustration: isset() determines the existence of the variable The average execution time is between 0.0010-0.0011 seconds3. empty() determines the existence of a variable Illustration: isset() determines the existence of a variable. The average execution time is between 0.0010-0.0011 seconds. Based on the above test performance , it can be seen that the execution time of isset() and empty() functions is basically the same. The average execution time of the two functions is between 0.0010-0.0011 seconds. Of course, this is related to the specific environment. From the current test environment, the two functions Performance is the same. http://www.bkjia.com/PHPjc/444717.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444717.htmlTechArticleThe article uses charts to tell you about the comparison of execution time and performance of PHP isset() and empty() functions. Bad, friends in need can take a look at it in detail. The performance test uses Benchmark_...
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