diff options
author | Remi Collet <remi@remirepo.net> | 2019-10-23 13:29:12 +0200 |
---|---|---|
committer | Remi Collet <remi@remirepo.net> | 2019-10-23 13:29:12 +0200 |
commit | 261032f77820d0b620707ace75cfa82043558581 (patch) | |
tree | b94e3a12c0ed1af50793fe699eaa75fbbe87dc07 /zstd.php | |
parent | 2dfbea225f695ad6f66309b754e50b58eb6bde9f (diff) |
cleanup Zstd ex
Diffstat (limited to 'zstd.php')
-rw-r--r-- | zstd.php | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -1,4 +1,5 @@ -<?php +<?php declare(strict_types=1); + /** * ZSTD compressor using FFI and libzstd * PoC, only for documentation purpose @@ -22,15 +23,19 @@ if (PHP_SAPI == "cli" && !class_exists("\\Remi\\Zstd")) { if (class_exists("\\Remi\\Zstd")) { $t = microtime(true); - $ret = \Remi\Zstd::compress(PHP_BINARY, "testffi.zstd"); - printf("\nSrc length = %d\n", $ret['in_len']); - printf("ZSTD_compressBound = %d\n", $ret['max_len']); - printf("ZSTD_compress = %d\n", $ret['out_len']); + $src = file_get_contents(PHP_BINARY); + $comp = \Remi\Zstd::compress($src); + printf("\nSrc length = %d\n", \strlen($src)); + printf("ZSTD_compress = %d\n", \strlen($comp)); + file_put_contents("testffi.zstd", $comp); + + $comp = file_get_contents("testffi.zstd"); + $out = \Remi\Zstd::decompress($comp); + printf("Src length = %d\n", \strlen($comp)); + printf("ZSTD_decompress = %d\n", \strlen($out)); + file_put_contents("testffi.orig", $out); - $ret = \Remi\Zstd::decompress("testffi.zstd", "testffi.orig"); - printf("Src length = %d\n", $ret['in_len']); - printf("ZSTD_decompressBound = %d\n", $ret['max_len']); - printf("ZSTD_decompress = %d\n", $ret['out_len']); + printf("Check = %s\n", $src === $out ? "OK" : "KO"); $t = microtime(true) - $t; printf("Using FFI extension = %.3f\"\n\n", $t); @@ -51,12 +56,13 @@ if (extension_loaded("zstd")) { file_put_contents("testzstd.zstd", $comp); $comp = file_get_contents("testzstd.zstd"); + printf("Src length = %d\n", \strlen($comp)); $unco = zstd_uncompress($comp); $ulen = strlen($unco); printf("ZSTD_decompress = %d\n", $ulen); file_put_contents("testzstd.orig", $unco); - var_dump($src === $unco); + printf("Check = %s\n", $src === $unco ? "OK" : "KO"); $t = microtime(true) - $t; printf("Using ZSTD extension = %.3f\"\n\n", $t); } else { |