IT
정렬 된 배열을 정렬되지 않은 배열을 처리하는 것보다 빨리 처리하는 이유는 무엇입니까?
질문다음은 매우 특이한 행동을 보여주는 C ++ 코드 조각입니다.이상한 이유로, 데이터를 기적적으로 루프를 거의 6 배 더 빨리 분류합니다.#include #include #include int main() { // Generate data const unsigned arraySize = 32768; int data[arraySize]; for (unsigned c = 0; c < arraySize; ++c) data[c] = std::rand() % 256; // !!! With this, the next loop runs faster. std::sort(data, data + arraySize); // Test clock_t start = clock(); long long sum = 0; for (u..
2022. 3. 23. 10:35
최근댓글