| PHP & Web Development :: PHP
Performance + Benchmarking :: Testing String Variables |
Testing String Variables
Though
various development books have their own opinion of using strlen(),
empty(), and isset() (most say don't use strlen to validate strings
because of performance considerations), I have always wondered as
to their factual validity now that PHP is in its fifth incantation.
This server unfortunately does not use the latest stable version of
PHP, PHP5, but rather the tried and tested PHP4 which is still in
wide use.
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 |
strlen()
|
- Execution time: 4.94
ms
- Average: 7.09
ms over 1128 trials
|
empty()
|
- Execution time: 2.92
ms
- Average: 3.08
ms over 1128 trials
|
isset()
|
- Execution time: 2.34
ms
- Average: 2.51
ms over 1128 trials
|
|