Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $sa = array('some string', '', 'test1', 'test2', '');
- $length = count($sa);
- $b = false;
- $limit = 1000000;
- $times = $limit*$length;
- $start = microtime(true);
- for($i = 0; $i < $limit; $i++){
- foreach($sa as $s){
- $b = (strlen($s) > 0);
- }
- }
- echo 'strlen() > 0 used '.$times.' times in ' . (microtime(true) - $start) . ' msec' . "\n\n";
- $start = microtime(true);
- for($i = 0; $i < $limit; $i++){
- foreach($sa as $s){
- $b = ($s !== '');
- }
- }
- echo 'var !== \'\' used '.$times.' times in ' . (microtime(true) - $start) . ' msec' . "\n\n";
- $start = microtime(true);
- for($i = 0; $i < $limit; $i++){
- foreach($sa as $s){
- $b = !empty($s);
- }
- }
- echo '!empty() used '.$times.' times in ' . (microtime(true) - $start) . ' msec' . "\n\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement