// MemoryTest.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h"
int main(int argc, char* argv[])
{
size_t ticksT11a = 0;
size_t ticksT11b = 0;
size_t ticksT12a = 0;
size_t ticksT12b = 0;
size_t ticksT13a = 0;
size_t ticksT13b = 0;
size_t ticksT14a = 0;
size_t ticksT14b = 0;
int loops = 0;
srand(0);
for(loops = 0;loops<10;loops++)
{
printf("\n\nLOOP %d\n",loops);
printf("Test 1.1: 2 Werte ohne Shifting\n");
clock_t c_1 = clock();
BYTE* arr_1 = (BYTE*)malloc(2000000); //2 MB
if(arr_1 == NULL) return -1;
for(int i = 0;i<2000000;i+=2)
{
arr_1[i] = rand()%16;
arr_1[i+1] = rand()%16;
}
ticksT11a += clock()-c_1;
printf("%d clock ticks sind vergangen, um den Array zu beladen.\n",clock()-c_1);
c_1 = clock();
for(int i = 0;i<2000000;i+=2)
{
BYTE b1 = arr_1[i];
BYTE b2 = arr_1[i+1];
}
ticksT11b += clock()-c_1;
printf("%d clock ticks sind vergangen, um den Array auszulesen.\n",clock()-c_1);
free(arr_1);
printf("Test 1.2: 2 Werte mit Shifting\n");
c_1 = clock();
arr_1 = (BYTE*)malloc(1000000); //1 MB
if(arr_1 == NULL) return -2;
for(int i = 0;i<1000000;i++)
{
BYTE b1 = rand()%16;
BYTE b2 = rand()%16;
arr_1[i] = b2 | (b1 << 4);
}
ticksT12a += clock()-c_1;
printf("%d clock ticks sind vergangen, um den Array zu beladen.\n",clock()-c_1);
c_1 = clock();
for(int i = 0;i<1000000;i++)
{
BYTE b1 = arr_1[i] >> 4;
BYTE b2 = arr_1[i] ^ (b1 << 4);
}
ticksT12b += clock()-c_1;
printf("%d clock ticks sind vergangen, um den Array auszulesen.\n",clock()-c_1);
free(arr_1);
printf("Test 1.3: 2 Werte ohne Shifting, 10x groesser\n");
c_1 = clock();
arr_1 = (BYTE*)malloc(20000000); //2 MB
if(arr_1 == NULL) return -1;
for(int i = 0;i<20000000;i+=2)
{
arr_1[i] = rand()%16;
arr_1[i+1] = rand()%16;
}
ticksT13a += clock()-c_1;
printf("%d clock ticks sind vergangen, um den Array zu beladen.\n",clock()-c_1);
c_1 = clock();
for(int i = 0;i<20000000;i+=2)
{
BYTE b1 = arr_1[i];
BYTE b2 = arr_1[i+1];
}
ticksT13b += clock()-c_1;
printf("%d clock ticks sind vergangen, um den Array auszulesen.\n",clock()-c_1);
free(arr_1);
printf("Test 1.4: 2 Werte mit Shifting, 10x groesser\n");
c_1 = clock();
arr_1 = (BYTE*)malloc(10000000); //10 MB
if(arr_1 == NULL) return -2;
for(int i = 0;i<10000000;i++)
{
BYTE b1 = rand()%16;
BYTE b2 = rand()%16;
arr_1[i] = b2 | (b1 << 4);
}
ticksT14a += clock()-c_1;
printf("%d clock ticks sind vergangen, um den Array zu beladen.\n",clock()-c_1);
c_1 = clock();
for(int i = 0;i<10000000;i++)
{
BYTE b1 = arr_1[i] >> 4;
BYTE b2 = arr_1[i] ^ (b1 << 4);
}
ticksT14b += clock()-c_1;
printf("%d clock ticks sind vergangen, um den Array auszulesen.\n",clock()-c_1);
free(arr_1);
}
printf("\n\n\t\tSUMMARY\n"
"Total ticks Test 1.1: %d\n"
"\t1.1a: %d\n"
"\t1.1b: %d\n"
"Total ticks Test 1.2: %d\n"
"\t1.2a: %d\n"
"\t1.2b: %d\n"
"Total ticks Test 1.3: %d\n"
"\t1.3a: %d\n"
"\t1.3b: %d\n"
"Total ticks Test 1.4: %d\n"
"\t1.4a: %d\n"
"\t1.4b: %d\n",ticksT11a+ticksT11b,ticksT11a,ticksT11b,ticksT12a+ticksT12b,ticksT12a,ticksT12b,ticksT13a+ticksT13b,ticksT13a,ticksT13b,ticksT14a+ticksT14b,ticksT14a,ticksT14b);
printf("\n\n\t\tAVERAGE\n"
"1.1: %d\n"
"1.2: %d\n"
"1.3: %d\n"
"1.4: %d\n", (ticksT11a+ticksT11b)/loops, (ticksT12a+ticksT12b)/loops, (ticksT13a+ticksT13b)/loops, (ticksT14a+ticksT14b)/loops);
system("PAUSE");
return 0;
}