Skip to content

Instantly share code, notes, and snippets.

@dktapps
Created May 30, 2021 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dktapps/8a5d839f4c884f92d0b56f04c3b7d7d4 to your computer and use it in GitHub Desktop.
Save dktapps/8a5d839f4c884f92d0b56f04c3b7d7d4 to your computer and use it in GitHub Desktop.
<?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);
@fwflunky
Copy link

fwflunky commented Jul 2, 2022

xd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment