[pmwiki-users] zlib.output_compression_level

Anno anno at shroomery.org
Fri Sep 29 06:30:21 CDT 2006


> If that is true then why is the default setting 
> set to 6 ?????

I don't know.

Here is the output of a test script (the source is at the bottom, feel free to
check for yourself)

Lenght original: 740190

Level: 0
Lenght: 740306
Ratio: 1.0001567165187
Time: 26.66711807251 msec

Level: 1
Lenght: 198763
Ratio: 0.26852970183331
Time: 47.888040542603 msec

Level: 2
Lenght: 191513
Ratio: 0.25873491941258
Time: 50.992012023926 msec

Level: 3
Lenght: 185913
Ratio: 0.25116929437036
Time: 53.215980529785 msec

Level: 4
Lenght: 173752
Ratio: 0.2347397289885
Time: 71.269989013672 msec

Level: 5
Lenght: 168856
Ratio: 0.22812521109445
Time: 81.506013870239 msec

Level: 6
Lenght: 167266
Ratio: 0.22597711398425
Time: 107.92899131775 msec

Level: 7
Lenght: 166514
Ratio: 0.22496115862144
Time: 119.34900283813 msec

Level: 8
Lenght: 166224
Ratio: 0.22456936732461
Time: 129.15514945984 msec

Level: 9
Lenght: 166228
Ratio: 0.22457477134249
Time: 132.77101516724 msec


As you can see, level 6 takes more than 100% more time to do the job compare to
level 2, for additional ~3% size reduction.

It is on you to decide whether it is worth it.


The script:
<?php

$file=get_file_contents();

for ($level = 0; $level <= 9; $level++) {
	if ($level==0) echo "Lenght original: ".strlen($file)."<br><br>";
	$time_start = microtime_float();
	$compressed = gzcompress($file, $level);
	$time_end = microtime_float();
	$time = ($time_end - $time_start)*1000;
	echo 
	"Level: ".$level.
	"<br>Lenght: ".strlen($compressed).
	"<br>Ratio: ".strlen($compressed)/strlen($file).
	"<br>Time: ".$time." msec<br><br>";
}



function microtime_float()
{
   list($usec, $sec) = explode(" ", microtime());
   return ((float)$usec + (float)$sec);
}

function get_file_contents()
{
	$filename = "file.htm";
	$handle = fopen($filename, "r");
	$contents = fread($handle, filesize($filename));
	fclose($handle);
	return $contents;
}












More information about the pmwiki-users mailing list