- #1
Monte_Carlo
- 72
- 0
Hi guys,
I've been given the code below and asked to explain the data shown in the attached chart. Any ideas? The data shows periodicity, what could explain it? I know it has to do with memory.
Thanks,
Monte
I've been given the code below and asked to explain the data shown in the attached chart. Any ideas? The data shows periodicity, what could explain it? I know it has to do with memory.
Code:
-------------------------------------------------------
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>
#include <math.h>
#include <windows.h>
#include <memory.h>
static LARGE_INTEGER liStart;
static LARGE_INTEGER liStop;
using namespace std;
int main(){
int n = 10000000;
int k = 0;
ofstream outFile ("out.txt");
for (int stepSize = 0; stepSize < 100000; stepSize += 128){
int * a = new int[n];
int x = 0;
for (int i = 0; i < n; i += 4096){
x += a[i+32];
}
QueryPerformanceCounter(&liStart);
x=0;
for (int i = 0; i < 100; i++){
x += a[i * stepSize];
}
QueryPerformanceCounter(&liStop);
outFile << stepSize << '\t' << liStop.QuadPart - liStart.QuadPart<<endl;;
outFile.flush();
delete [] a;
}
return(0);
}
-------------------------------------------------------
Thanks,
Monte
Attachments
Last edited by a moderator: