add linux little progs for locality
This commit is contained in:
parent
1dc0d0aa01
commit
2f904a1306
7
related_info/lab3/locality/Makefile
Normal file
7
related_info/lab3/locality/Makefile
Normal 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
related_info/lab3/locality/badlocality.c
Normal file
12
related_info/lab3/locality/badlocality.c
Normal 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
related_info/lab3/locality/goodlocality.c
Normal file
12
related_info/lab3/locality/goodlocality.c
Normal 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
related_info/lab3/locality/locality.md
Normal file
7
related_info/lab3/locality/locality.md
Normal file
@ -0,0 +1,7 @@
|
||||
#在linux下分析程序的局部性
|
||||
可通过如下命令在时间上看出在执行时间上的差异
|
||||
```
|
||||
make
|
||||
time ./goodlocality
|
||||
time ./badlocality
|
||||
```
|
Loading…
Reference in New Issue
Block a user