Cache misses when accessing an array in nested loop
问题 So I have this question from my professor, and I can not figure out why vector2 is faster and has less cache misses than vector1 . Assume that the code below is a valid compilable C code. Vector2: void incrementVector2(INT4* v, int n) { for (int k = 0; k < 100; ++k) { for (int i = 0; i < n; ++i) { v[i] = v[i] + 1; } } } Vector1: void incrementVector1(INT4* v, int n) { for (int i = 0; i < n; ++i) { for (int k = 0; k < 100; ++k) { v[i] = v[i] + 1; } } } NOTE: INT4 means the integer is 4 Bytes