那么实际上为什么我的周期不停地工作???它应该进行大约 100 次迭代,但它不会停止,请帮助。我拿了 min_block_size 这是我缓存 1 级的 10%,而 max_block_size 这是我的 l2 缓存的 10%!
#include <iostream>
#include <Windows.h>
#include <time.h>
#include <fstream>
#define MIN_BLOCK_SIZE 13108
#define MAX_BLOCK_SIZE 104858
#define STEP 1024
using namespace std;
int main()
{
setlocale(LC_CTYPE, "Russian");
int i, j, c, b;
clock_t c1, c2;
int*p = (int*) malloc(MAX_BLOCK_SIZE);
int tmp = 0;
LARGE_INTEGER start, finish, freq;
c1 = clock();
int n = 0;
for (b = 13108; b < 104858; b = +1024)
{
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
for (c = 0; c <= b; c += sizeof (int))
{
tmp += *(int*) ((int) p + c);
*(int*) ((int) p + c) = tmp;
}
QueryPerformanceCounter(&finish);
double time = (finish.QuadPart - start.QuadPart) / (double) freq.QuadPart;
n++;
cout << "Размер" << n << "блоков:" << (MIN_BLOCK_SIZE + 1024 * (n - 1)) << "KB" << endl;
cout << "Время o6pаботки" << n << "блоков" << time * 1000000 << "мкс" << endl;
cout << "время обработки одного елемента" << time * 1000000000 / (MIN_BLOCK_SIZE + 1024 * (n - 1)) << "наносек" << endl;
}
c2 = clock();
cout << "All the time is" << c2 - c1 << "sec";
cin.get();
cin.get();
return 0;
}