Advertisement
Guest User

Phalcon return value memory test

a guest
Aug 9th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. <?php
  2. // Create massive variable
  3. Mem::start();
  4. $string = str_repeat('a', 5000000);
  5. Mem::report('Creating $string: %s');
  6.  
  7. Mem::start();
  8. $rawValue = new Phalcon\Db\RawValue($string);
  9. Mem::report('Creating Phalcon RawValue: %s');
  10.  
  11. Mem::start();
  12. $tmp = $rawValue->getValue();
  13. Mem::report('Getting Phalcon string back: %s');
  14.  
  15. Mem::start();
  16. $tmp2 = $rawValue->getValue();
  17. Mem::report('Getting Phalcon string back again: %s');
  18.  
  19. echo "\n";
  20.  
  21. Mem::start();
  22. $string2 = str_repeat('a', 5000000);
  23. Mem::report('Creating $string2: %s');
  24.  
  25. Mem::start();
  26. $phpRawValue = new PhpRawValue($string2);
  27. Mem::report('Creating PhpRawValue: %s');
  28.  
  29. Mem::start();
  30. $tmpPhp = $phpRawValue->getValue();
  31. Mem::report('Getting PHP string back: %s');
  32.  
  33. Mem::start();
  34. $tmpPhp2 = $phpRawValue->getValue();
  35. Mem::report('Getting PHP string back again: %s');
  36.  
  37.  
  38. //---Functions--------------------------------------------
  39. class Mem
  40. {
  41.     protected static $_start;
  42.  
  43.     public static function start()
  44.     {
  45.         self::$_start = memory_get_usage();
  46.     }
  47.  
  48.     public static function report($message)
  49.     {
  50.         $current = memory_get_usage();
  51.         $difference = ($current - self::$_start) / 1000000;
  52.         echo sprintf($message, sprintf('%.2fM', $difference));
  53.         echo "\n";
  54.     }
  55. }
  56.  
  57. class PhpRawValue
  58. {
  59.     protected $_value;
  60.  
  61.     public function __construct($value)
  62.     {
  63.         $this->_value = $value;
  64.     }
  65.  
  66.     public function getValue()
  67.     {
  68.         return $this->_value;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement