Posts Tagged ‘optimization’

PHP hashing performance experiment

Sunday, April 25th, 2010

Today, in the never-ending quest to tweak server performance by a few milliseconds, I decided to do a bit of testing of various php hashing methods. I therefore wrote a quick script under php (5.2.11 currently, I need to update), which ran each test case 10,000 times to achieve a decent min/avg/max for each case, on strings of 10KB, 100KB, and 1,000KB in size.

The short version of the result is that the md5() function won across the board. The comments in the php.net hash function documentation seemed to indicate a performance increase in using hash(‘md5′,$str), and an even better increase in hash(‘md4′,$str). I found this to only partially be the case; While using the hash function, md4 is minutely faster than md5, the md5() function itself is considerably faster than either of these.

So, for any performance sensitive case, I would say md5() is by far the best choice.

Actual results of the test suite can be seen here:

PHP Hash Performance by JSylvanus via Listy.us

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post