PHP isset () vs. empty () function execution time comparison _php tutorial

Source: Internet
Author: User
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_ ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.