PHP uses the Hash_algos function to calculate the hash value between the performance sort

Source: Internet
Author: User

PHP starting from 5.1.2 version support Hash_algos function, see this name to know, Algos in English also means the meaning of the algorithm, Hash_algos is the hashing algorithm, collected some common hashing algorithm, Starting with different versions of PHP from 5.1.2, the supported algorithms are slightly different.

Here I write a function that can see all the hashing algorithms supported by my version of PHP and calculate their performance comparisons.


<?php

Set_time_limit (300);
Define (' CNT ', 50000);
$algos = Hash_algos ();
foreach ($algos as $algo) {
$st = Microtime ();
for ($i = 0; $i < CNT; $i + +) {
Hash ($algo, Microtime (). $i);
}
$et = Microtime ();
List ($SS, $si) = Explode (", $st);
List ($es, $ei) = Explode (", $et);
$time [$algo] = $ei + $es-$si-$ss;
$time [$algo]. = "[Sample:". Hash ($algo, "HELLO World"). "]";
}
Asort ($time, sort_numeric);
echo "<table>";
foreach ($time as $key = = $value) {
echo "<tr><td> $key </td><td> $value </td></tr>";
}
echo "</table>";


The results are as follows:

fnv164 0.37478698735046 [sample:eaab5a330ee5b36f]
Md4 0.3985438946991 [Sample:c85e5fdf3a18840f9041ac70f241deb0]
crc32b 0.41961007745361 [sample:87e5865b]
fnv132 0.42863700695801 [sample:4240512f]
tiger160,3 0.43971493786621 [sample:5ffd501e367bed4d8e103761f66fad075ff4af41]
Adler32 0.44000594578552 [sample:128b031d]
Joaat 0.46947299908447 [sample:0b1cc760]
ripemd128 0.49671197273254 [Sample:34f326051d6c45d698add89721159ce4]
sha224 0.51215290837097 [SAMPLE:906BBEE30415AAB29F8309B829B521BB4275DE9A302B37480AB129E9]
Md5 0.52081801637268 [sample:361fadf1c712e812d198c4cab5712a79]
Sha1 0.53381191786194 [sample:4b68507f1746b0e5f3efe99b8ef42afef79da017]
sha256 0.54046505882263 [SAMPLE:787EC76DCAFD20C1908EB0936A12F91EDD105AB5CD7ECC2B1AE2032648345DFF]
tiger128,3 0.54758100090027 [SAMPLE:5FFD501E367BED4D8E103761F66FAD07]
ripemd160 0.5674130983429 [SAMPLE:3219B86078ED4B3DA3D7CF681144AB933C0938B2]
Crc32 0.58168091377258 [sample:299ffb96]
haval128,3 0.59623603713989 [SAMPLE:10B8533D416BE012F54F5BF090635F2A]
ripemd256 0.598747929245 [SAMPLE:281921C018530C2C00681CB9F7970368888A900E79160ED72BD578704FE1EEF5]
haval256,3 0.60667002838135 [sample:1534f6bfda22092180e3b737616f1e9b8f91508ead0199bb831d3a2ba57b621d]
ripemd320 0.63686393048096 [SAMPLE:89E3861212449BBD2577A890A02BE389B46AFEF606C4095302B182F7B88AB1A5B0E838095DC3A80E]
haval192,3 0.65839607575989 [sample:cfaf464019fc31f8e3346816ac195dc44314ee5061d47f81]
haval160,3 0.75110392315674 [SAMPLE:C937A75C444CE72FC7E0F216EE4FD66067F7C85D]
Whirlpool 0.75960894284058 [Sample : 153800a4da7dab37cf8d985f38edb51e34aa1c38b10db2c66a6727b249198df07ca0ecdd008bf2b3d3e5c6fddcc5e81b67ef5f090042941a9dcf8a6e ABD6A36C]
haval192,4 0.7767040065155 [sample:f231f85b193f40310bd063723d6645d9315729fc83daa729]
haval224,3 0.78067902493286 [sample:a3ea3ea3b3f39f7417c75132e0a49ef8d06e4af1bfbe9fb6a448f72b]
tiger192,3 0.78198196318054 [sample:5ffd501e367bed4d8e103761f66fad075ff4af41b5b9b31e]
sha512 0.79405710838318 [Sample : 13D6C73AC8CCEEFF9FF6B0BA2CE19C5FC47AC21F9FD403C151FE88E0FD39F4223C29BC9BDED59E1E3F272FD969FD6E2E6E35BE35072E742C4B36FEC4 8FEB87DF]
sha384 0.82325292324829 [Sample: D3E23B4F16EA11C71ABA0D23BA04A5625482A33BDCC69E63E2B86122470D22CF906BDBBCB204E73EC1338C8508BB2E2A]
haval256,4 0.83586111834717 [sample:ca671b39d8bf0bbb3d24a6883a4b907cd9413591d69e8b5c775dd6a2168570f0]
haval128,4 0.84537810420227 [sample:fa039d416e0ebb1a8e4d2e09e1187956]
tiger160,4 0.85183900819397 [Sample:10f15bbde5f13452c365c54d1623ba99b0c052be]
haval224,5 0.8582429559021 [sample:0ad3fd38c1fdaa22c425af43ba805893ae8b1daf7b2e8b2c1910821a]
haval160,4 0.85876092556763 [Sample:85937b88a871dc814e70b9fb185ea9c6c0f698e5]
haval256,5 0.91796088124084 [SAMPLE:90C751CD8F632217AF98F8D72E9DA4123ED7221C6091FA877E1A158264CBA3A6]
haval192,5 0.94244197169495 [sample:f64e4497f83c6a91ec5dcc0e2c074593b5ee37898304153d]
tiger192,4 0.95719099984741 [SAMPLE:10F15BBDE5F13452C365C54D1623BA99B0C052BE228B4E5A]
haval160,5 1.020770897995 [Sample:c091f42b8f48de9c6a9cbaecc2f2962b74d882f8]
haval224,4 1.0293329506226 [Sample:bb68e9358e71067cd20db808bfeb69575772ee4e8c11b51431672fd4]
haval128,5 1.0518960091553 [SAMPLE:69B36B8FFB85C66A395137CC89CD70BD]
tiger128,4 1.0905900340881 [Sample:10f15bbde5f13452c365c54d1623ba99]
Gost 1.1367739732208 [SAMPLE:B0278F172B9F94C86D8344C28E58B8727C0396F6DFB11648070EC188D53BEF44]
Md2 1.2356340056915 [sample:8a4b081d657c2099cbfaee796217759f]
snefru256 1.381886079422 [sample:2ffb1850bb73024a262f842c5e7dbbe37256b6a1562b8b6c95d3a5c0d3b29f5b]
Snefru 1.6106969665833 [sample:2ffb1850bb73024a262f842c5e7dbbe37256b6a1562b8b6c95d3a5c0d3b29f5b]


Can see fnv164 the fastest, Sha512 and MD5 in the performance of the comparison, MD5 will be slightly faster, but not obvious, and Sha512 is more secure than MD5, but because the number of bits is too long, storage space occupies a lot, if using MD5 (SHA512 ()), then, is a more eclectic and excellent algorithm.


Article reprinted from: Http://www.ttmd5.com/article.php?id=14

PHP uses the Hash_algos function to calculate the hash value between the performance sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.