TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

2 点作者 hagbart_celine大约 14 年前
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

2 条评论

garlicbreadftw大约 14 年前
Is there an md5 function that returns a primitive type?<p>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.)<p>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大约 14 年前
uhm, strcmp by far. md5 is computationally expensive and strcmp can have many optimizations.