note 89574 added to function.hash

From: Date: Sat, 14 Mar 2009 11:20:23 +0000
Subject: note 89574 added to function.hash
Groups: php.notes 
Request: Send a blank email to php-notes+get-151864@lists.php.net to get a copy of this message
Performance test results on my laptop: Results are here shorten to fit php web notes ... This was tested with 1024000 bytes (1000 KB) of random data, md4 always gets the first place, and md2 always get the last place :) Results: (in microseconds) 1. md4 5307.912 2. md5 6890.058 3. crc32b 7298.946 4. crc32 7561.922 5. sha1 8886.098 6. tiger128,3 11054.992 7. haval192,3 11132.955 8. haval224,3 11160.135 9. tiger160,3 11162.996 10. haval160,3 11242.151 11. haval256,3 11327.981 12. tiger192,3 11630.058 13. haval128,3 11880.874 14. tiger192,4 14776.945 15. tiger128,4 14871.12 16. tiger160,4 14946.937 17. haval160,4 15661.954 18. haval192,4 15717.029 19. haval256,4 15759.944 20. adler32 15796.184 21. haval128,4 15887.022 22. haval224,4 16047.954 23. ripemd256 16245.126 24. haval160,5 17818.927 25. haval128,5 17887.115 26. haval224,5 18085.002 27. haval192,5 18135.07 28. haval256,5 18678.903 29. sha256 19020.08 30. ripemd128 20671.844 31. ripemd160 21853.923 32. ripemd320 22425.889 33. sha384 45102.119 34. sha512 45655.965 35. gost 57237.148 36. whirlpool 64682.96 37. snefru 80352.783 38. md2 705397.844 Code for generating this: (compatible both with browser and cli mode) <pre> <?php echo 'Building random data ...' . PHP_EOL; @ob_flush();flush(); $data = ''; for ($i = 0; $i < 64000; $i++) $data .= hash('md5', rand(), true); echo strlen($data) . ' bytes of random data built !' . PHP_EOL . PHP_EOL . 'Testing hash algorithms ...' . PHP_EOL; @ob_flush();flush(); $results = array(); foreach (hash_algos() as $v) { echo $v . PHP_EOL; @ob_flush();flush(); $time = microtime(true); hash($v, $data, false); $time = microtime(true) - $time; $results[$time * 1000000000][] = "$v (hex)"; $time = microtime(true); hash($v, $data, true); $time = microtime(true) - $time; $results[$time * 1000000000][] = "$v (raw)"; } ksort($results); echo PHP_EOL . PHP_EOL . 'Results: ' . PHP_EOL; $i = 1; foreach ($results as $k => $v) foreach ($v as $k1 => $v1) echo ' ' . str_pad($i++ . '.', 4, ' ', STR_PAD_LEFT) . ' ' . str_pad($v1, 30, ' ') . ($k / 1000) . ' microseconds' . PHP_EOL; ?> </pre> ---- Server IP: 193.198.184.18 Probable Submitter: 89.201.177.57 ---- Manual Page -- http://www.php.net/manual/en/function.hash.php Edit -- https://master.php.net/note/edit/89574 Del: integrated -- https://master.php.net/note/delete/89574/integrated Del: useless -- https://master.php.net/note/delete/89574/useless Del: bad code -- https://master.php.net/note/delete/89574/bad+code Del: spam -- https://master.php.net/note/delete/89574/spam Del: non-english -- https://master.php.net/note/delete/89574/non-english Del: in docs -- https://master.php.net/note/delete/89574/in+docs Del: other reasons-- https://master.php.net/note/delete/89574 Reject -- https://master.php.net/note/reject/89574 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151864) next »