

Ask HN: "strcmp" or "if(md5(str1) == md5(str2))"? - hagbart_celine

I need to compare to strings (hashes consisting of numbers and letters). Now i'm thingking about performance... is it better, to use strcmp or md5 both strings and compare with a if-statement?<p>*edit: it's in a web-app using php
======
garlicbreadftw
Is there an md5 function that returns a primitive type?

The ones I know of return structs or arrays, which you can't compare via == in
C. (I assume you're using C since strcmp is used for C strings.)

If you already have the md5's precomputed, they're probably less data, so it
would be faster in that case. If you include the time to compute md5, then
strcmp is definitely faster. Intuitively, strcmp just needs to do one very
fast pass over the strings, with just a single comparison per character; while
md5 needs to do a lot more work just to compute its output.

------
spitfire
uhm, strcmp by far. md5 is computationally expensive and strcmp can have many
optimizations.

