Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Исходный код для статьи http://anton-pribora.ru/articles/php/php-rerfomance/
- */
- $start = microtime(true);
- $cycles = 0;
- $elapsed = 0;
- $result = '';
- do {
- $loops = 1000;
- $begin = microtime(true);
- do {
- // Тестируемая операция
- $result .= new A(array('foo' => 'bar'));
- } while (--$loops);
- $cycles += 1000;
- $elapsed += microtime(true) - $begin;
- } while (microtime(true) - $start < 1);
- printf("%s: %.0f cycle/sec, %s bytes, %s bytes/cycle\n", PHP_VERSION, $cycles / $elapsed, strlen($result), strlen($result) / $cycles);
- class A
- {
- private $foo;
- private $bar;
- private $baz;
- private $bee;
- public function __construct($array)
- {
- foreach($this as $prop => $value) {
- if ( isset($array[$prop]) ) {
- $this->{$prop} = $array[$prop];
- }
- }
- }
- public function __toString()
- {
- $result = array();
- foreach($this as $prop => $value) {
- $result[] = $prop .': '. $this->{$prop};
- }
- return join("\n", $result);
- }
- }
Add Comment
Please, Sign In to add comment