选什么哈希运算方法做唯一标识运算

@admin  December 29, 2016

<p>首先先介绍下php的哈希运算。</p>
<p>http://php.net/manual/zh/ref.hash.php<;/p>
<p>php封装了很多哈希运算方法,我们可以直接使用这些方法,而不用去研究算法的实现。php支持的哈希算法可以通过函数hash_algos()看到。 </p>
<p>通过脚本我生成了各个算法的运行时间</p>
<p> </p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;">Array( </span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;">[tiger192,3] => 0.24838397525024</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [tiger128,4] => 0.28798002894592</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [tiger160,3] => 0.37073995600891</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [tiger128,3] => 0.37840509146118 </span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;">[ripemd128] => 0.40955311077881</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [ripemd256] => 0.41773602061462</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [ripemd160] => 0.4244598936615</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [fnv1a32] => 0.42722491441345</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [fnv132] => 0.42827295285034</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [adler32] => 0.42828211448669 </span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;">[sha256] => 0.43280292050171</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [joaat] => 0.4357079349823 </span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;">[crc32b] => 0.44724404898071</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [ripemd320] => 0.44913201341248</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [fnv1a64] => 0.46072790139771</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [fnv164] => 0.4618910300293</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> [crc32] => 0.46863598667908</span></p>
<p><span style="color:#444444;font-family:&quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, STHeiti,serif;font-size:14px;"> )</span></p>
<p>

</p>
<p>可以看出如果想要做唯一标识运算 tiger192,3 是个不错的选择(hash("tiger192,3",$value,false))。只不过我的php版本是5.6x 。有可能你的版本不支持这个哈希算法。你需要在自己的服务器测试一下看看哪个最合适。 </p>


添加新评论