Skip to content

Instantly share code, notes, and snippets.

@vudaltsov
Last active November 18, 2023 22:50
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 vudaltsov/bda0272d2c09250a4541487579a468b4 to your computer and use it in GitHub Desktop.
Save vudaltsov/bda0272d2c09250a4541487579a468b4 to your computer and use it in GitHub Desktop.
Кэш через OPcache
<?php
use Typhoon\Exporter\Exporter;
require_once 'vendor/autoload.php';
final class City
{
public function __construct(
public string $name,
public int $code,
) {
}
}
$rnd = new City('Ростов-на-Дону', 863);
file_put_contents('var/serialize', serialize($rnd));
file_put_contents('var/igbinary', igbinary_serialize($rnd));
file_put_contents('var/code', "<?php return new City('Ростов-на-Дону', 863);");
touch('var/code', time() - 10);
file_put_contents('var/typhoon', sprintf('<?php return %s;', Exporter::export($rnd)));
touch('var/typhoon', time() - 10);
file_put_contents('var/serialize_code', sprintf("<?php return unserialize(%s);", var_export(serialize($rnd), true)));
touch('var/serialize_code', time() - 10);
DragonCode\Benchmark\Benchmark::start()
->withoutData()
->round(2)
->compare([
'serialize' => static function (): void {
unserialize(file_get_contents('var/serialize'));
},
'igbinary' => static function (): void {
igbinary_unserialize(file_get_contents('var/igbinary'));
},
'code' => static function (): void {
include 'var/code';
},
'typhoon' => static function (): void {
include 'var/typhoon';
},
'serialize_code' => static function (): void {
include 'var/serialize_code';
},
]);
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^8.2",
"typhoon/exporter": "^0.2.0"
"dragon-code/benchmark": "^2.5"
}
}
$ php -d extension="igbinary.so" -d opcache.enable_cli=1 benchmark.php
------- ------------------- ------------------- ------------------- ------------------- -------------------
# serialize igbinary code typhoon serialize_code
------- ------------------- ------------------- ------------------- ------------------- -------------------
min 0.14 ms - 0 bytes 0.15 ms - 0 bytes 0 ms - 0 bytes 0.01 ms - 0 bytes 0 ms - 0 bytes
max 0.28 ms - 0 bytes 0.25 ms - 0 bytes 0.26 ms - 0 bytes 0.69 ms - 0 bytes 0.28 ms - 0 bytes
avg 0.23 ms - 0 bytes 0.22 ms - 0 bytes 0 ms - 0 bytes 0.01 ms - 0 bytes 0 ms - 0 bytes
total 21.98 ms 20.37 ms 1.01 ms 2.09 ms 1.46 ms
------- ------------------- ------------------- ------------------- ------------------- -------------------
Order - 5 - - 4 - - 1 - - 3 - - 2 -
------- ------------------- ------------------- ------------------- ------------------- -------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment