Hello. I am writing a program to determine the size of the second-level cache line, I used the article habrahabr.ru/post/93263. But I get completely different results. Through the Coreinfo program, I learned that the size of the first and second level strings is 64 bytes each. So far I have decided to get at least the size of the first level row, but some completely inadequate results are obtained.
#include "stdafx.h" #include <time.h> #include <iostream> #include <string> using namespace std; int main() { int t; const int N = 8000; volatile int arr[N]; unsigned int A; char ask1 = 'y'; srand(time(NULL)); while (ask1 == 'y') { for (int j = 0; j < N; j++) arr[j] = rand(); for (int i = 1; i <= 64; i++) { A = clock(); for (int k = 0; k < 100000; k++) for (int j = 0; j < N; j += i) { t = arr[j]; } //cout << i << "\tstep, time\t" << clock() - A << '\t' << t << endl; arr[i] = (clock() - A); //Вместо печати, чтобы не рушить кэш, я решил занести время выполнения в тот же самый массив, а потом его вывести } for (int i = 1; i <= 64; i++) cout << i << "\tstep, time\t" << arr[i] << endl; cout << "Repeat?(y/n): "; cin >> ask1; cout << endl; } /**/ const int n = 1600000000; int l; unsigned int a; char ask = 'y'; srand(time(NULL)); //это просто для рандома, чтобы он был разный, хотя тут мне это и не особо нужно while (ask == 'y') { volatile int byte8[2]; for (int j = 0; j < 2; j++) byte8[j] = rand(); //рандомим массив a = clock();//записываем время до циклов считывания массива for (int k = 0; k < n / 2; k++) /*делим n на количество повторений внутреннего цикла, чтобы везде в сумме получилось одинаковое число повторений */ for (int i = 0; i < 2; i++) l = byte8[i]; cout << size(byte8) * 4 << "\tbytes\t" << clock() - a << endl; //выводим количество ms понадобившихся для считывания //далее повторяем то же самое для массивов большей длинны volatile int byte16[4]; for (int j = 0; j < 4; j++) byte16[j] = rand(); a = clock(); for (int k = 0; k < n / 4; k++) for (int i = 0; i < 4; i++) l = byte16[i]; cout << size(byte16) * 4 << "\tbytes\t" << clock() - a << endl; volatile int byte32[8]; for (int j = 0; j < 8; j++) byte32[j] = rand(); a = clock(); for (int k = 0; k < n / 8; k++) for (int i = 0; i < 8; i++) l = byte32[i]; cout << size(byte32) * 4 << "\tbytes\t" << clock() - a << endl; /* int byte60[15]; for (int j = 0; j < 15; j++) byte60[j] = rand(); a = clock(); for (int k = 0; k < n / 15; k++) for (int i = 0; i < 15; i++) l = byte60[i]; cout << size(byte60) * 4 << "\tbytes\t" << clock() - a << endl; */ volatile int byte64[16]; for (int j = 0; j < 16; j++) byte64[j] = rand(); a = clock(); for (int k = 0; k < n / 16; k++) for (int i = 0; i < 16; i++) l = byte64[i]; cout << size(byte64) * 4 << "\tbytes\t" << clock() - a << endl; /* int byte68[17]; for (int j = 0; j < 17; j++) byte68[j] = rand(); a = clock(); for (int k = 0; k < n / 17; k++) for (int i = 0; i < 17; i++) l = byte68[i]; cout << size(byte68) * 4 << "\tbytes\t" << clock() - a << endl; */ volatile int byte96[24]; for (int j = 0; j < 24; j++) byte96[j] = rand(); a = clock(); for (int k = 0; k < n / 24; k++) for (int i = 0; i < 24; i++) l = byte96[i]; cout << size(byte96) * 4 << "\tbytes\t" << clock() - a << endl; volatile int byte128[32]; for (int j = 0; j < 32; j++) byte128[j] = rand(); a = clock(); for (int k = 0; k < n / 32; k++) for (int i = 0; i < 32; i++) l = byte128[i]; cout << size(byte128) * 4 << "\tbytes\t" << clock() - a << endl; volatile int byte192[48]; for (int j = 0; j < 48; j++) byte192[j] = rand(); a = clock(); for (int k = 0; k < n / 48; k++) for (int i = 0; i < 48; i++) l = byte192[i]; cout << size(byte192) * 4 << "\tbytes\t" << clock() - a << endl; volatile int byte256[64]; for (int j = 0; j < 64; j++) byte256[j] = rand(); a = clock(); for (int k = 0; k < n / 64; k++) for (int i = 0; i < 64; i++) l = byte256[i]; cout << size(byte256) * 4 << "\tbytes\t" << clock() - a << endl; volatile int byte512[128]; for (int j = 0; j < 128; j++) byte512[j] = rand(); a = clock(); for (int k = 0; k < n / 128; k++) for (int i = 0; i < 128; i++) l = byte512[i]; cout << size(byte512) * 4 << "\tbytes\t" << clock() - a << endl; cout << "Repeat?(y/n): "; cin >> ask; cout << endl; } system("pause"); return 0; } The fact is that I cannot use functions of the GetLogicalProcessorInformation type; I need to define a test. I launch in Visual Studio 2017 with a configuration on Release

