]> git.mxchange.org Git - hub.git/blob - mhash-benchmark.php
moved for svn-git transission
[hub.git] / mhash-benchmark.php
1 <?php
2 error_reporting(0);
3 set_time_limit(0);
4
5 /*
6  * Note: I could use mhash_count() here but I like to see unavailable hashers
7  * because this is important to me to choose the most-available hasher(s) and
8  * those with the best speed/secure tradeoff.
9  */
10 $hasher = array(
11         MHASH_ADLER32,
12         MHASH_CRC32,
13         MHASH_CRC32B,
14         MHASH_GOST,
15         MHASH_HAVAL128,
16         MHASH_HAVAL160,
17         MHASH_HAVAL192,
18         MHASH_HAVAL224,
19         MHASH_HAVAL256,
20         MHASH_MD2,
21         MHASH_MD4,
22         MHASH_MD5,
23         MHASH_RIPEMD128,
24         MHASH_RIPEMD256,
25         MHASH_RIPEMD320,
26         MHASH_SHA1,
27         MHASH_SHA192,
28         MHASH_SHA224,
29         MHASH_SHA256,
30         MHASH_SHA384,
31         MHASH_SHA512,
32         MHASH_SNEFRU128,
33         MHASH_SNEFRU256,
34         MHASH_TIGER,
35         MHASH_TIGER128,
36         MHASH_TIGER160,
37         MHASH_WHIRLPOOL
38 );
39
40 $timers = array();
41 $count = 500 * 1000;
42
43 print 'Iterating ' . $count . ' times over all ' . count($hasher) . ' mhash hashers ...' . "\r\n";
44
45 foreach ($hasher as $hash) {
46         // Is this no number, the hasher is not available
47         if (!is_int($hash)) {
48                 $timers[str_replace('MHASH_', '', $hash)] = '- unavailable -';
49                 continue;
50         } // END - if
51
52         $time = microtime(true);
53         for ($idx = 0; $idx <= $count; $idx++) {
54                 $dummy = bin2hex(mhash($hash, 'mhash-test-abc-123-foo-bar'));
55         } // END - for
56
57         $timers[mhash_get_hash_name($hash)] = (microtime(true) - $time);
58         print '.';
59 } // END - foreach
60
61 print "\r\n\r\n";
62 asort($timers);
63
64 print 'Result from mhash() benchmark (in seconds per hasher):' . "\r\n";
65 print_r($timers) . "\n";
66
67 ?>