Skip to content

Instantly share code, notes, and snippets.

@dktapps
Created May 30, 2021
Embed
What would you like to do?
<?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