Guest User

Untitled

a guest
May 22nd, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. class A {
  3.     public $a;
  4.  
  5.     public function set($a) {
  6.         $this->a = $a;
  7.     }
  8.  
  9.     public function bind(&$a) {
  10.         $this->a = &$a;
  11.     }
  12. }
  13.  
  14. $i = $m1 = $m2 = 0;
  15.  
  16. echo "start: ", xdebug_memory_usage(), "\n";
  17.  
  18. $a = new A();
  19. for (; $i < 100000; $i++) {
  20.     $b[] = array('c' => $i);
  21. }
  22.  
  23. echo "after generating: ", $m1 = xdebug_memory_usage(), "\n";
  24.  
  25. switch ($argv[1]) {
  26.     case "s":
  27.         echo "setting...\n";
  28.         $a->set($b);
  29.         break;
  30.     case "b":
  31.         echo "binding...\n";
  32.         $a->bind($b);
  33.         break;  
  34. }
  35.  
  36. echo "after action: ", xdebug_memory_usage(), "\n";
  37.  
  38. foreach ($a->a as $i) {
  39.     foreach ($i as $inner) {
  40.         continue;
  41.     }
  42. }
  43.  
  44. echo "after iterating: ", $m2 = xdebug_memory_usage(), "\n";
  45. echo "difference: ", $m2 - $m1, "\n";
Advertisement
Add Comment
Please, Sign In to add comment