示例#1
0
 /**
  * Determines the byte size of an object.
  *
  * @param object $object the object to examine
  * @param string $unit the unit
  * @throws Exception
  * @return string a human readable string describing the result
  */
 public static function sizeOfObject($object, $unit = 'kBytes')
 {
     if (is_object($object)) {
         $name = get_class($object);
     } elseif (is_array($object)) {
         $name = 'array';
     } elseif ($object === NULL) {
         $name = 'null';
     } else {
         $name = 'unknown';
     }
     $old = memory_get_usage(true);
     $dummy = unserialize(serialize($object));
     $mem = memory_get_usage(true);
     $text = new Text();
     $size = $text->convertBytes((int) abs($mem - $old));
     return "Object [{$name}] memory usage: {$size[0]} {$size[1]}";
 }
示例#2
0
 /**
  * Tests the bytes to human readable string conversion.
  *
  * @dataProvider convertBytesProvider
  * @covers empire\framework\util\Text::convertBytes
  *
  * @param $bytes the bytes to convert
  * @param $iec whether to use iec names
  * @param $res the result
  */
 public function testConvertBytes($bytes, $iec, $res)
 {
     $this->assertSame($res, $this->instance->convertBytes($bytes, $iec));
 }