这是一段看似非常特殊的C++代码.出于某种奇怪的原因,奇迹般地对数据进行排序使得代码几乎快了六倍.
#include <algorithm>
#include <ctime>
#include <iostream>
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 (unsigned i = 0; i < 100000; ++i)
{
// Primary loop
for (unsigned c = 0; c < arraySize; ++c) …Run Code Online (Sandbox Code Playgroud) 什么是SMP中的TLB击落?
我无法找到有关此概念的更多信息.任何好的例子都会非常感激.
我读了这个问题,描述了TLB击落的内容.我试图了解这是由内核或处理器执行的操作还是两者兼而有之?
我的问题是: -
tlb ×2
c++ ×1
caching ×1
java ×1
kernel ×1
linux ×1
optimization ×1
performance ×1
smp ×1
x86 ×1