Re: Hashing strings
| From: | Gerard Samuel | Date: | Fri, 18 Feb 2005 02:18:29 +0000 |
| Subject: | Re: Hashing strings | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-208983@lists.php.net to get a copy of this message | ||
Jason Barnett wrote:
Gerard Samuel wrote: ...I normally profile with apd, but it only measures in the hundredth of a second. So I used getrusage() & memory_get_usage() functions to *unscientifically* profile md5()/sha1()/crc32() on FreeBSD 5.3. I ran a for loop 75 times, hashing the constant __FILE__ These are an average of 5 runs -> ---- md5: Usertime -> 784.2 µsec Systemtime -> 72.2 µsec...Im trying to determine if md5() would be the fastest, *cheapest* solution.What Im looking for is something where the generated hashes can be reproduced. For example, md5('foo') today, will be equal to md5('foo') tomorrow. ThanksAFAIK crc32() is the fastest hashing function in PHP. I don't have actual results on hand still, but I created a filesystem plugin that auto-generates hashes for each file in a directory. crc32() was faster than md5() and sha1(). FYI the benchmarking that I did was for a Windows XP system... YMMV
Memory -> 120.0 bytessha1: Usertime -> 846.8 µsec Systemtime -> 150.2 µsec
Memory -> 80.0 bytes
crc32:
Usertime -> 194.8 µsec
Systemtime -> 54.2 µsec
Memory -> 80.0 bytesCan you shed some light on that code, that you're using for the filesystem plugin? Thanks