summaryrefslogtreecommitdiffstats
path: root/zstd.php
diff options
context:
space:
mode:
Diffstat (limited to 'zstd.php')
-rw-r--r--zstd.php26
1 files changed, 16 insertions, 10 deletions
diff --git a/zstd.php b/zstd.php
index 7faebea..0ec22d7 100644
--- a/zstd.php
+++ b/zstd.php
@@ -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 {