Browse Source

add linux little progs for locality

main
yuchen 9 years ago
parent
commit
2f904a1306
4 changed files with 38 additions and 0 deletions
  1. +7
    -0
      related_info/lab3/locality/Makefile
  2. +12
    -0
      related_info/lab3/locality/badlocality.c
  3. +12
    -0
      related_info/lab3/locality/goodlocality.c
  4. +7
    -0
      related_info/lab3/locality/locality.md

+ 7
- 0
related_info/lab3/locality/Makefile 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

+ 12
- 0
related_info/lab3/locality/badlocality.c 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);
}

+ 12
- 0
related_info/lab3/locality/goodlocality.c 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);
}

+ 7
- 0
related_info/lab3/locality/locality.md View File

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

Loading…
Cancel
Save