The length and performance test examples of various hash algorithms implemented by PHP, And the hash performance test

Source: Internet
Author: User

The length and performance test examples of various hash algorithms implemented by PHP, And the hash performance test

This article describes the length and performance tests of various hash algorithms implemented by PHP. We will share this with you for your reference. The details are as follows:

The Hash result is as follows:

<?php$data = "hello world";foreach (hash_algos() as $v) {    $r = hash($v, $data, false);    printf("%-12s %3d %s\n", $v, strlen($r), $r);}?>

Running result:

md2      32 d9cce882ee690a5c1ce70beff3a78c77md4      32 aa010fbc1d14c795d86ef98c95479d17md5      32 5eb63bbbe01eeed093cb22bb8f5acdc3sha1     40 2aae6c35c94fcfb415dbe95f408b9ce91ee846edsha224    56 2f05477fc24bb4faefd86517156dafdecec45b8ad3cf2522a563582bsha256    64 b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9sha384    96 fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bdsha512    128 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76fripemd128   32 c52ac4d06245286b33953957be6c6f81ripemd160   40 98c615784ccb5fe5936fbc0cbe9dfdb408d92f0fripemd256   64 0d375cf9d9ee95a3bb15f757c81e93bb0ad963edf69dc4d12264031814608e37ripemd320   80 0e12fe7d075f8e319e07c106917eddb0135e9a10aefb50a8a07ccb0582ff1fa27b95ed5af57fd5c6whirlpool  128 8d8309ca6af848095bcabaf9a53b1b6ce7f594c1434fd6e5177e7e5c20e76cd30936d8606e7f36acbef8978fea008e6400a975d51abe6ba4923178c7cf90c802tiger128,3  32 4c8fbddae0b6f25832af45e7c62811bbtiger160,3  40 4c8fbddae0b6f25832af45e7c62811bb64ec3e43tiger192,3  48 4c8fbddae0b6f25832af45e7c62811bb64ec3e43691e9cc3tiger128,4  32 24465a3f6e4aa92d903ee535476591e9tiger160,4  40 24465a3f6e4aa92d903ee535476591e937f3a14dtiger192,4  48 24465a3f6e4aa92d903ee535476591e937f3a14d81c4c7b6snefru    64 902b49fa8b0828b44d8ac069111899bbfaf51d334485e4b28e90c93f63bb86ddsnefru256   64 902b49fa8b0828b44d8ac069111899bbfaf51d334485e4b28e90c93f63bb86ddgost     64 1bb6ce69d2e895a78489c87a0712a2f40258d1fae3a4666c23f8f487bef0e22agost-crypto  64 c5aa1455afe9f0c440eec3c96ccccb5c8495097572cc0f625278bd0da5ea5e07adler32    8 1a0b045dcrc32     8 7813f744crc32b     8 0d4a1185fnv132     8 548da96ffnv1a32    8 d58b3fa7fnv164    16 7dcf62cdb1910e6ffnv1a64    16 779a65e7023cd2e7joaat     8 3e4a5a57haval128,3  32 906c1df7cbe6d318f36ab172f95e89c0haval160,3  40 6e733b21876e47c2168a122e23d86bdd69e50f95haval192,3  48 ec67a6a417953fdbf3496502004b6c21b270d5890dedd931haval224,3  56 766879d9ba1dc9e24a6040908a7ae813a47b08af5c5f3beebcacda48haval256,3  64 45492c6c8adab277759f4381420799431a037daf6d829b8b5c21104c10f61a92haval128,4  32 c97d46956b8e3e60acd2bb090c482c5ehaval160,4  40 2cb8b12eb5a2561022010c2a2af8795e602fdef2haval192,4  48 39a281e4e492533b6dfea0af294149ccac771ab87204c9echaval224,4  56 3d64d34aea48f5e649ed6147da5d29d31c762a937e9e21f4da1f3106haval256,4  64 0359a526d77e271707c44d9b270e68a394f8486a459f0137ad5e1d02e44c5889haval128,5  32 8332ad9f32e385d9acd421b63ee04cfchaval160,5  40 d33cf9052d55da9b0f506cb8849097939363e361haval192,5  48 67c3492878c8fc4819c8589231fcfe69b15b015c1ca48ac5haval224,5  56 6bedeb6a8676e46413c020c8813c022486ca93353b8a0673fb577ba1haval256,5  64 f5f6ffcfe39a65ac2c3989430340420341762a6624ebd69b9d08ec1dc4b9f167

The performance test is as follows:

<?phpdefine('testtime', 1000000);$algos = hash_algos();foreach($algos as $algo) {  $st = microtime();  for($i = 0; $i < testtime; $i++) {    hash($algo, microtime().$i);  }  $et = microtime();  list($ss, $si) = explode(' ', $st);  list($es, $ei) = explode(' ', $et);  $time[$algo] = $ei + $es - $si - $ss;}asort($time, SORT_NUMERIC);print_r($time);?>

Running result:

Array(  [fnv1a32] => 1.4528379546356  [fnv164] => 1.4598390410767  [fnv1a64] => 1.4685498960724  [fnv132] => 1.4695508840027  [crc32b] => 1.480463955719  [adler32] => 1.481206043457  [joaat] => 1.4851269485474  [crc32] => 1.508364085907  [md4] => 1.6973789288788  [md5] => 1.7637529927979  [sha1] => 1.932477017334  [tiger128,3] => 1.9683119142761  [tiger160,3] => 1.9759550503387  [ripemd128] => 2.0003409449921  [tiger192,3] => 2.0107291056519  [tiger128,4] => 2.0609339611664  [tiger160,4] => 2.0614830404358  [ripemd256] => 2.1055679496613  [tiger192,4] => 2.1089930283813  [ripemd320] => 2.3564790057831  [ripemd160] => 2.3820580299072  [sha256] => 2.3944439311981  [sha224] => 2.4205659084473  [haval128,3] => 2.5319820201874  [haval224,3] => 2.5319839861755  [haval160,3] => 2.5347460784149  [haval192,3] => 2.5500600071869  [haval256,3] => 2.580485933548  [sha384] => 2.6736448852386  [sha512] => 2.721533025589  [haval224,4] => 2.9019400155029  [haval128,4] => 2.9155439011078  [haval256,4] => 2.9168769813385  [haval160,4] => 2.9341630749512  [haval192,4] => 2.9478991126251  [haval192,5] => 3.1933639251862  [haval256,5] => 3.1942859609985  [haval160,5] => 3.1946619862823  [whirlpool] => 3.1954451004639  [haval128,5] => 3.2122300287323  [haval224,5] => 3.295264964798  [gost] => 4.6756690344391  [gost-crypto] => 4.6819899302826  [snefru] => 6.5784390528107  [snefru256] => 6.6484970919647  [md2] => 11.291653894501)

PS: Here are two hash-related online tools for your reference:

Online hash/hash algorithm encryption tool:
Http://tools.jb51.net/password/hash_encrypt

Online MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 encryption tools:
Http://tools.jb51.net/password/hash_md5_sha

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.