diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index c2eb214de..0a9bd6f7f 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -234,7 +234,7 @@ class Binary{ * @return int */ public static function readShort($str, $signed = true){ - list(, $unpacked) = @unpack("n", $str); + $unpacked = @unpack("n", $str)[1]; if($unpacked > 0x7fff and $signed === true){ $unpacked -= 0x10000; // Convert unsigned short to signed short } @@ -266,7 +266,7 @@ class Binary{ * @return int */ public static function readLShort($str, $signed = true){ - list(, $unpacked) = @unpack("v", $str); + $unpacked = @unpack("v", $str)[1]; if($unpacked > 0x7fff and $signed === true){ $unpacked -= 0x10000; // Convert unsigned short to signed short } @@ -290,7 +290,7 @@ class Binary{ } public static function readInt($str){ - list(, $unpacked) = @unpack("N", $str); + $unpacked = @unpack("N", $str)[1]; if($unpacked > 2147483647){ $unpacked -= 4294967296; } @@ -303,7 +303,7 @@ class Binary{ } public static function readLInt($str){ - list(, $unpacked) = @unpack("V", $str); + $unpacked = @unpack("V", $str)[1]; if($unpacked >= 2147483648){ $unpacked -= 4294967296; } @@ -316,9 +316,7 @@ class Binary{ } public static function readFloat($str){ - list(, $value) = ENDIANNESS === self::BIG_ENDIAN ? @unpack("f", $str) : @unpack("f", strrev($str)); - - return $value; + return ENDIANNESS === self::BIG_ENDIAN ? @unpack("f", $str)[1] : @unpack("f", strrev($str))[1]; } public static function writeFloat($value){ @@ -326,9 +324,7 @@ class Binary{ } public static function readLFloat($str){ - list(, $value) = ENDIANNESS === self::BIG_ENDIAN ? @unpack("f", strrev($str)) : @unpack("f", $str); - - return $value; + return ENDIANNESS === self::BIG_ENDIAN ? @unpack("f", strrev($str))[1] : @unpack("f", $str)[1]; } public static function writeLFloat($value){ @@ -340,9 +336,7 @@ class Binary{ } public static function readDouble($str){ - list(, $value) = ENDIANNESS === self::BIG_ENDIAN ? @unpack("d", $str) : @unpack("d", strrev($str)); - - return $value; + return ENDIANNESS === self::BIG_ENDIAN ? @unpack("d", $str)[1] : @unpack("d", strrev($str))[1]; } public static function writeDouble($value){ @@ -350,9 +344,7 @@ class Binary{ } public static function readLDouble($str){ - list(, $value) = ENDIANNESS === self::BIG_ENDIAN ? @unpack("d", strrev($str)) : @unpack("d", $str); - - return $value; + return ENDIANNESS === self::BIG_ENDIAN ? @unpack("d", strrev($str))[1] : @unpack("d", $str)[1]; } public static function writeLDouble($value){ diff --git a/src/tests/Benchmark.php b/src/tests/Benchmark.php index e914cb215..0c6c9dcc2 100644 --- a/src/tests/Benchmark.php +++ b/src/tests/Benchmark.php @@ -21,6 +21,7 @@ use pocketmine\level\generator\noise\Perlin; use pocketmine\level\generator\noise\Simplex; +use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\network\raknet\Packet; use pocketmine\utils\Binary; @@ -110,6 +111,19 @@ $score += 1000 * ($taken / $expect); echo round($taken, 6)."s\n"; +$expect = 0.4; +echo "[*] Measuring AA Bounding Box [$expect]... "; +$bb = new AxisAlignedBB(12, 219, 21, 15, 59, 51); +$start = microtime(true); +for($i = $iterations; $i > 0; --$i){ + $bb = $bb->getOffsetBoundingBox(1, 2, -1); +} +$taken = microtime(true) - $start; +$score += 1000 * ($taken / $expect); +++$tests; +echo round($taken, 6)."s\n"; + + $expect = 2.5; echo "[*] Measuring file operations [$expect]... "; $start = microtime(true); @@ -123,7 +137,7 @@ echo round($taken, 6)."s\n"; $expect = 4.5; -echo "[*] Simple Packet decoding [$expect]... "; +echo "[*] Measuring Simple Packet decoding [$expect]... "; $packet = hex2bin("8401000000000815"); $start = microtime(true); for($i = $iterations; $i > 0; --$i){ @@ -139,7 +153,7 @@ echo round($taken, 6)."s\n"; $expect = 0.1; -echo "[*] microtime() operations [$expect]... "; +echo "[*] Measuring microtime() operations [$expect]... "; $start = microtime(true); for($i = $iterations; $i > 0; --$i){ microtime(true);