summaryrefslogtreecommitdiff
path: root/tests/compare/compress.php
diff options
context:
space:
mode:
authorGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2026-07-12 15:51:52 +0300
committerGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2026-07-12 15:51:52 +0300
commit02608271bb2a9f3a65ed536984d306ee14b48e34 (patch)
tree3f23ec48a694ec014e845c4f70d9b5f1c065403c /tests/compare/compress.php
downloadkalassa-master.tar.gz
kalassa-master.tar.bz2
kalassa-master.zip
initialize repository; add docker config; migrate configuration to new specsHEADmaster
Diffstat (limited to 'tests/compare/compress.php')
-rwxr-xr-xtests/compare/compress.php80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/compare/compress.php b/tests/compare/compress.php
new file mode 100755
index 0000000..f36baa2
--- /dev/null
+++ b/tests/compare/compress.php
@@ -0,0 +1,80 @@
+<?php
+
+echo "test started... ";
+ob_flush();
+
+Benchmark::add_spot('query-10000-products');
+$db = Registry::use('database');
+$products = $db->runQuery("SELECT * FROM products LIMIT 10000",[]);
+
+
+
+$originalLength = $compressLength = 0;
+Benchmark::add_spot('gzcompress(1)-10000-products');
+foreach($products as $product) {
+ $original = serialize($product);
+ $compress = gzcompress($original, 1);
+ $originalLength = strlen($original);
+ $compressLength = strlen($compress);
+}
+echo "<pre>gzcompress(1)
+compressed {$originalLength} to {$compressLength} or ";
+echo ($originalLength-$compressLength)*100/$originalLength ."%\n</n>";
+
+
+
+$originalLength = $compressLength = 0;
+Benchmark::add_spot('gzcompress(4)-10000-products');
+foreach($products as $product) {
+ $original = serialize($product);
+ $compress = gzcompress($original, 4);
+ $originalLength = strlen($original);
+ $compressLength = strlen($compress);
+}
+echo "<pre>gzcompress(4)
+compressed {$originalLength} to {$compressLength} or ";
+echo ($originalLength-$compressLength)*100/$originalLength ."%\n</n>";
+
+
+
+$originalLength = $compressLength = 0;
+Benchmark::add_spot('gzcompress(6)-10000-products');
+foreach($products as $product) {
+ $original = serialize($product);
+ $compress = gzcompress($original, 6);
+ $originalLength = strlen($original);
+ $compressLength = strlen($compress);
+}
+echo "<pre>gzcompress(6)
+compressed {$originalLength} to {$compressLength} or ";
+echo ($originalLength-$compressLength)*100/$originalLength ."%\n</n>";
+
+
+
+$cache = Registry::use('cache');
+
+Benchmark::add_spot('Cache-save-10000-products');
+foreach($products as $product) {
+ $cache->set('cache.sav.'.$product['ID'], serialize($product), 3600);
+}
+
+
+
+Benchmark::add_spot('gz(ser(),6)+Save-10000-products');
+foreach($products as $product) {
+ $cache->set('zx.ser.sav.'.$product['ID'], gzcompress(serialize($product), 6), 3600);
+}
+
+$maxLen = 0;
+Benchmark::add_spot('sha1(serialize())-10000-products');
+foreach($products as $product) {
+ $original = sha1(serialize($product));
+ $maxlen = $maxLen > strlen($original) ? $maxLen : strlen($original);
+}
+
+
+Benchmark::add_spot('end');
+echo(Benchmark::report(BENCH_REPORT_COMMENT));
+
+echo "test completed!";
+die();