Created
May 30, 2021 12:37
-
-
Save dktapps/8a5d839f4c884f92d0b56f04c3b7d7d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace test; | |
use function hrtime; | |
use function printf; | |
class BinaryStream{ | |
protected string $buffer = ""; | |
protected $buffer2 = ""; | |
public function put(string $str) : void{ | |
$this->buffer .= $str; | |
} | |
public function put2(string $str) : void{ | |
$this->buffer2 .= $str; | |
} | |
} | |
$stream = new BinaryStream(); | |
$loops = 100_000; | |
$start = hrtime(true); | |
for($i = 0; $i < $loops; $i++){ | |
$stream->put("\xaa\xbb\xcc\xdd"); | |
} | |
printf("Typed property time: %g ns/op\n", (hrtime(true) - $start) / $loops); | |
$start = hrtime(true); | |
for($i = 0; $i < $loops; $i++){ | |
$stream->put2("\xaa\xbb\xcc\xdd"); | |
} | |
printf("Typeless property time: %g ns/op\n", (hrtime(true) - $start) / $loops); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
xd