add linux little progs for locality

This commit is contained in:
yuchen 2015-03-23 09:11:45 +08:00
parent 1dc0d0aa01
commit 2f904a1306
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,7 @@
all: goodlocality badlocality
goodlocality:
gcc -O0 -g -o goodlocality goodlocality.c
badlocality:
gcc -O0 -g -o badlocality badlocality.c
clean:
rm goodlocality badlocality

View File

@ -0,0 +1,12 @@
#include <stdio.h>
#define NUM 1024
#define COUNT 10
int A[NUM][NUM];
void main (void) {
int i,j,k;
for (k = 0; k<COUNT; k++)
for (j = 0; j < NUM; j++)
for (i = 0; i < NUM; i++)
A[i][j] = 0;
printf("%d count computing over!\n",i*j*k);
}

View File

@ -0,0 +1,12 @@
#include <stdio.h>
#define NUM 1024
#define COUNT 10
int A[NUM][NUM];
void main (void) {
int i,j,k;
for (k = 0; k<COUNT; k++)
for (i = 0; i < NUM; i++)
for (j = 0; j < NUM; j++)
A[i][j] = i+j;
printf("%d count computing over!\n",i*j*k);
}

View File

@ -0,0 +1,7 @@
#在linux下分析程序的局部性
可通过如下命令在时间上看出在执行时间上的差异
```
make
time ./goodlocality
time ./badlocality
```