对3402285大小的字符串进行10000次执行sha1,md5,crc32这3个函数的测试,得出结果如下:
字符串大小:3402285
连续执行次数:10000
执行结果:
sha1: 288.353684秒
md5: 157.227909秒
crc32: 128.691496秒
crc32的效率比md5要快22%
执行:php test_sha1_md5_crc32.php crc32 file_nme 1000
附上脚本:
[php]
< ?php
/*
* Name: test_sha1_md5_crc32.php
* Date: 2008-01-03
* Author: bixuan
*/
if ($argc != 4)
{
echo "php test.php sha1|md5|crc32 file_name count\n";
exit;
}
if (!file_exists($argv[2]))
{
echo $argv[2]." is not exists.\n";
exit;
}
if(!is_numeric($argv[3]))
{
echo $argv[3]." is not int.\n";
exit;
}
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
$file = $argv[2];
$file_size = filesize($file);
$fc = file_get_contents($file);
$i=$argv[3];
for($k=0;$k< $i;$k++)
{
if ($argv[1] == "sha1")
{
echo $k.":".sha1($fc)."\n";
}elseif($argv[1] == "md5")
{
echo $k.":".md5($fc)."\n";
}elseif($argv[1] == "crc32")
{
echo $k.":".crc32($fc)."\n";
}else
{
echo "error.\n";
break;
}
}
$time_end = microtime_float();
$time = $time_end - $time_start;
//echo $time."
";
$time = sprintf("%01.6f", $time);
echo "\n";
echo "Algorithm:\t".$argv[1]."\nFileName\t".$file."\nFileSize:\t".$file_size."Bytes\nCostTime:\t$time Sec.\n";
unset($file_size);
unset($fc);
?>
[/php]
How big should I set the TCP window size?
In theory the TCP window size should be set to the product of the available bandwidth of the network and the round trip time of data going over the network. For example if a network had a bandwidth of 100 Mbits/s and the round trip time was 5 msec, the TCP window should be 100×10^6 times 5×10^-3 or 500×10^3 bits (65 kilobytes).
The easiest way to determine the round trip time is to use ping from one host to the another and use the response times returned by ping.
Note that many architectures have limits on the size of the socket buffer and hence the TCP window size. Typically these are on the order of a megabyte