]> git.mxchange.org Git - core.git/blob - contrib/hash-benchmark.php
Continued:
[core.git] / contrib / hash-benchmark.php
1 #!/usr/bin/env php
2 <?php
3 error_reporting(0);
4 set_time_limit(0);
5
6 /*
7  * Note: I could use mhash_count() here but I like to see unavailable hashers
8  * because this is important to me to choose the most-available hasher(s) and
9  * those with the best speed/secure tradeoff.
10  */
11 $hasher = hash_algos();
12
13 $timers = array();
14 $count = 500 * 1000;
15
16 print 'Iterating ' . $count . 'x over all ' . count($hasher) . ' hash functions ...' . "\r\n";
17
18 foreach ($hasher as $hash) {
19         $time = microtime(true);
20         for ($idx = 0; $idx <= $count; $idx++) {
21                 $dummy = hash($hash, 'hash-test-abc-123-foo-bar');
22         }
23
24         $timers[$hash] = (microtime(true) - $time);
25         print '.';
26 }
27
28 print "\r\n\r\n";
29 asort($timers);
30
31 print 'Result from hash() benchmark (in seconds per hasher):' . "\r\n";
32 print_r($timers) . "\n";