Guest User

php & vs if

a guest
Apr 15th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. <?php
  2.  
  3. $arr = array();
  4. for($i = 0; $i < 100000; ++$i) {
  5.     $arr[$i] = (rand() % 2 === 0 ? '0' : '1');
  6. }
  7.  
  8. $t1 = microtime();
  9. for($i = 0; $i < 100000; ++$i) {
  10.     $arr[$i] = '1' & $arr[$i];
  11. }
  12. echo microtime() - $t1;
  13. echo "\n";
  14.  
  15. $t1 = microtime();
  16. for($i = 0; $i < 100000; ++$i) {
  17.     if($arr[$i] == '1')
  18.         $arr[$i] = '1';
  19.     else
  20.         $arr[$i] = '0';
  21. }
  22. echo microtime() - $t1;
Advertisement
Add Comment
Please, Sign In to add comment