| PHP & Web Development :: PHP
Performance + Benchmarking :: Testing Boolean Variables |
Testing Boolean Variables
Testing
booleans is a common code occurance in programs, and I have been trying
to be a good programmer and use $var===true (=== means exactly equal,
== means equivalent.) However, I also worry about performance, and
I suspect that using the exactly equal to comparison is slowing down
scripts where I'm doing many, many comparisons.
Test Environment: Linux, Apache, PHP 4.3.11 with
PHP loaded using FastCGI. Zend Optimizer 2.5.7 installed. What's
Zend Optimizer?
Test Setup: Code constructs listed below. For loops
used to have enough iterations to make the script execution time calculatable.
Refresh the page to execute a new trial!
| Comparisons |
($var)
|
- Execution time: 0.37
ms
- Average: 0.29
ms over 965 trials
|
$var==true
|
- Execution time: 1.07
ms
- Average: 0.53
ms over 965 trials
|
$var===true
|
- Execution time: 0.42
ms
- Average: 0.46
ms over 965 trials
|
|