Why my C++ code slows down significantly when array size is 8192?
Hi everyone. I'm writing a C++ program for image processing. I discovered a strange problem: when the size of my array (or loop step) is exactly 8192 elements, the program starts running 10 times slower. With size 8191 or 8193, everything is fast.\n\nHere's simplified code that reproduces the problem:\n\n```cpp\n#include \n#include \n#include \n\nint main() {\n const int SIZE = 8192;\n // If changed to 8191 or 8193 — speed is normal\n std::vector> matrix(SIZE, std::vector(SIZE, 1));\n\n auto start = std::chrono::high_resolution_clock::now();\n\n long long sum = 0;\n for (int i = 0; i < SIZE; ++i) {\n for (int j = 0; j < SIZE; ++j) {\n sum += matrix[i][j];\n }\n }\n\n auto end = std::c
No answers yet.
Log in to leave an answer