TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

1B Nested Loop Iterations

1 pointsby pbrowne0117 months ago

2 comments

Someone7 months ago
The C code is different, doing a bit more than the JavaScript, Python and Go versions:<p><pre><code> int main() { long array[10000]; for (int i = 0; i &lt; 10000; i++) { for (int j = 0; j &lt; 100000; j++) { array[i] = array[i] + j + i; &#x2F;&#x2F; on that page array[i] = array[i] + j; &#x2F;&#x2F; what it should be } } } </code></pre> I suspect&#x2F;guess they added that to avoid the case where the C compiler is too smart, and forgot to make the other programs do the same thing.<p>Also: what do they do to prevent the C compiler from removing that entire bit of code? If they don’t read the resulting data, it may well do that.
fuhsnn7 months ago
To be fair, GCC even at -O1 knows the looped statement is non-observable, it&#x27;s entirely optimized out: <a href="https:&#x2F;&#x2F;godbolt.org&#x2F;z&#x2F;afjz9h471" rel="nofollow">https:&#x2F;&#x2F;godbolt.org&#x2F;z&#x2F;afjz9h471</a>