Comparison of execution time between PHP isset () and empty () functions

Source: Internet
Author: User
Tags benchmark

, Test environment
Operating system: Window XP
PHP Version: PHP Version 5.2.11
Apache version: Apache 2.0 Handler

II. Test method
Use Benchmark_Iterate to test isset () and empty 50 times and generate a chart if the variable exists and does not exist

3. isset () and empty () determine if the variable does not exist.
1. Test code

The code is as follows: Copy code

Require_once "Benchmark/Iterate. php ";
$ Tenant = new Benchmark_Iterate;
Function check1 ($ var ){
Isset ($ var );
}
Function check2 ($ var ){
! Empty ($ var );
}
$ Activities-> run (50, "check1", $ var );
// $ Response-> run (50, "check2", $ var );
$ Result = $ response-> get ();


$ Var variable is not initialized to determine whether the variable does not exist. The execution performance of the two functions is shown in the figure below.

2. isset () determines if the variable does not exist.

Illustration: when isset () judges that a variable does not exist, the average execution time is between 0.0010 and 0.0011 seconds.
3. empty () determines if the variable does not exist.


Illustration: empty () determines that the variable does not exist. The average execution time is between 0.0010 and 0.0011 seconds.
4. isset () and empty () determine the existence of variables

, Test code

The code is as follows: Copy code

Require_once "Benchmark/Iterate. php ";
$ Tenant = new Benchmark_Iterate;
 
Function check1 ($ var ){
Isset ($ var );
}
Function check2 ($ var ){
! Empty ($ var );
}
$ Var = true;
$ Activities-> run (50, "check1", $ var );
// $ Response-> run (50, "check2", $ var );
$ Result = $ response-> get ();

Initialize the $ var variable to true to determine whether the variable exists. The execution performance of the two functions is as follows:

2. isset () determines the existence of a variable

Illustration: isset () determines the existence of a variable. The average execution time is between 0.0010 and 0.0011 seconds.
3. empty () is used to determine the existence of a variable.
Illustration: isset () determines the existence of a variable. The average execution time is between 0.0010 and 0.0011 seconds.
Based on the test performance, we can see 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 performance of the two functions is the same.
 

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.