Hacker News new | past | comments | ask | show | jobs | submit login
1B Nested Loop Iterations (benjdd.com)
1 point by pbrowne011 4 days ago | hide | past | favorite | 2 comments





The C code is different, doing a bit more than the JavaScript, Python and Go versions:

  int main() {
    long array[10000];
    for (int i = 0; i < 10000; i++) {
      for (int j = 0; j < 100000; j++) {
        array[i] = array[i] + j + i; // on that page
        array[i] = array[i] + j; // what it should be
      }
    }
  }
I suspect/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.

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.


To be fair, GCC even at -O1 knows the looped statement is non-observable, it's entirely optimized out: https://godbolt.org/z/afjz9h471



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: