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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Good old-fashioned code optimization never goes out of style

4 点作者 itamarst超过 2 年前

1 comment

deaddabe超过 2 年前
&gt; Data structures and algorithms: We used a dictionary instead of a list to go from O(S) to O(1) operations.<p>The list in TFA is so small that I wonder at what point creating a hashtable is more economical than going through a 9 items arrays. In C, accounting for allocations, etc. I would not be surprised that strcmp on an static array would be faster.<p>As always, measure with benchmarks (which does the article, but not on array vs. hashtable). In theory, O(1) is better than O(N). In pratice, with memory allocations and all, the order of magnitude of N plays a role.<p>Anyways, I would have used a hashtable also to convey the <i>idea</i> that I only want to check if the item is in the list. Python makes this easy. In C, I would have used an array unless N is &quot;large enough&quot;.