Created
September 30, 2021 14:39
-
-
Save sammarshallou/f1491184c1eb1ee62901f07cff2bea20 to your computer and use it in GitHub Desktop.
Test for compress/decompress performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('memory_limit', '8G'); | |
$raw = file_get_contents('lib.tar'); | |
$length = strlen($raw); | |
echo "Loaded file " . $length . " bytes\n"; | |
$chunks = []; | |
for ($i = 0; $i < $length - 100*1024; $i += 100*1024) { | |
$chunks[] = substr($raw, $i, 100*1024); | |
} | |
echo "Created " . count($chunks) . " 100KB chunks\n"; | |
$compressed = []; | |
$before = microtime(true); | |
foreach ($chunks as $chunk) { | |
//$compressed[] = gzencode($chunk); | |
$compressed[] = zstd_compress($chunk); | |
} | |
$after = microtime(true); | |
$duration = $after - $before; | |
echo "Compressed " . round($duration, 3) . 's (per chunk ' . round(1000 * $duration / count($chunks), 1) . " ms)\n"; | |
$back = []; | |
$before = microtime(true); | |
foreach ($compressed as $chunk) { | |
//$back[] = gzencode($chunk); | |
$back[] = zstd_uncompress($chunk); | |
} | |
$after = microtime(true); | |
$duration = $after - $before; | |
echo "Deompressed " . round($duration, 3) . 's (per chunk ' . round(1000 * $duration / count($chunks), 1) . " ms)\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment