提交 5f2763dd 编写于 作者: R russelltao

add readme

上级 5bde8dc4
## 1. 验证环境
* 操作系统: CentOS7.0
* CPU: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
* GCC-C++: 4.8.5
* JAVA: 1.8.0
* Python: 2.7.5
## 2. C++程序branch_predict.cpp
### a. 编译程序
#### 安装编译依赖的软件
如Linux中需要安装gcc-c++,CentOS中可用`yum install gcc-c++`安装,Ubuntu中可用`apt-get install gcc-c++`
#### 编译程序
`g++ branch_predict.cpp -o branch_predict`
### b. 运行验证
#### 准备随机数组与排序好的数组
`./branch_predict -g`
该命令会在当前目录下生成随机数组rand.array文件和有序数组sort.array文件
#### 遍历随机数组
`./branch_predict -s`
消耗时间(毫秒):1000
#### 遍历有序数组
`./branch_predict -f`
消耗时间(毫秒):350
#### 遍历随机数组
`perf stat -e cache-references,cache-misses,instructions,cycles,L1-dcache-load-misses,L1-dcache-loads ./branch_predict -`
```
Performance counter stats for './branch_predict -s':
1,504,222,463 instructions # 0.49 insn per cycle
3,084,103,065 cycles
84,992 L1-icache-load-misses
67,153,573 branch-load-misses
273,893,334 branch-loads
1.040296121 seconds time elapsed
0.987243000 seconds user
0.053060000 seconds sys
```
#### 遍历有序数组
`perf stat -e cache-references,cache-misses,instructions,cycles,L1-dcache-load-misses,L1-dcache-loads ./branch_predict -f`
* 输出结果:
```
1,501,478,360 instructions # 1.27 insn per cycle
1,180,637,963 cycles
49,351 L1-icache-load-misses
27,282 branch-load-misses
273,404,227 branch-loads
0.404512198 seconds time elapsed
0.352686000 seconds user
0.051845000 seconds sys
```
## 1. 验证环境
* 操作系统: CentOS7.0
* CPU: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
* GCC-C++: 4.8.5
* JAVA: 1.8.0
* Python: 2.7.5
## 2. C++程序traverse_2d_array.cpp
### a. 编译程序
#### 安装编译依赖的软件
如Linux中需要安装gcc-c++,CentOS中可用`yum install gcc-c++`安装,Ubuntu中可用`apt-get install gcc-c++`
#### 编译程序
`g++ traverse_2d_array.cpp -o traverse_2d_array`
### b. 运行验证
#### 使用array[i][j]遍历数组
`./traverse_2d_array -f`
消耗时间(毫秒):10
#### 使用array[j][i]遍历数组
`./traverse_2d_array -s`
消耗时间(毫秒):70
### c. 使用perf验证缓存命中率
#### 使用array[i][j]遍历数组
`perf stat -e cache-references,cache-misses,instructions,cycles,L1-dcache-load-misses,L1-dcache-loads ./traverse_2d_array -f`
* 输出结果:
```
Performance counter stats for './traverse_2d_array -f':
147,927 cache-references (80.14%)
13,215 cache-misses # 8.933 % of all cache refs (65.49%)
54,454,827 instructions # 1.43 insn per cycle (85.11%)
38,197,267 cycles (85.09%)
161,503 L1-dcache-load-misses # 0.90% of all L1-dcache hits (85.09%)
18,035,307 L1-dcache-loads (84.19%)
0.020651344 seconds time elapsed
0.018625000 seconds user
0.002069000 seconds sys
```
#### 使用array[j][i]遍历数组
`perf stat -e cache-references,cache-misses,instructions,cycles,L1-dcache-load-misses,L1-dcache-loads ./traverse_2d_array -s`
* 输出结果:
```
Performance counter stats for './traverse_2d_array -s':
4,341,186 cache-references (83.01%)
13,974 cache-misses # 0.322 % of all cache refs (66.03%)
55,245,646 instructions # 0.25 insn per cycle (83.01%)
218,787,967 cycles (83.00%)
4,308,394 L1-dcache-load-misses # 23.79% of all L1-dcache hits (83.86%)
18,112,753 L1-dcache-loads (84.10%)
0.082950118 seconds time elapsed
0.079066000 seconds user
0.003953000 seconds sys
```
## 3. Java程序
### a. 编译程序
`javac traverse_2d_array.java`
### b.运行验证
#### 使用array[i][j]遍历数组
`java traverse_2d_array -f`
消耗时间(毫秒):20
#### 使用array[j][i]遍历数组
`java traverse_2d_array -s`
消耗时间(毫秒):100
### c. 使用perf验证缓存命中率
#### 使用array[i][j]遍历数组
`perf stat -e cache-references,cache-misses,instructions,cycles,L1-dcache-load-misses,L1-dcache-loads ./traverse_2d_array -f`
* 输出结果:
```
Performance counter stats for 'java traverse_2d_array -f':
6,379,138 cache-references (80.62%)
866,578 cache-misses # 13.585 % of all cache refs (68.93%)
459,726,039 instructions # 1.51 insn per cycle (85.22%)
303,673,757 cycles (85.69%)
5,270,707 L1-dcache-load-misses # 3.96% of all L1-dcache hits (81.64%)
133,211,743 L1-dcache-loads (83.13%)
0.126089887 seconds time elapsed
0.122353000 seconds user
0.047877000 seconds sys
```
#### 使用array[j][i]遍历数组
`perf stat -e cache-references,cache-misses,instructions,cycles,L1-dcache-load-misses,L1-dcache-loads ./traverse_2d_array -s`
* 输出结果:
```
Performance counter stats for 'java traverse_2d_array -s':
42,441,956 cache-references (80.21%)
872,336 cache-misses # 2.055 % of all cache refs (66.61%)
386,326,280 instructions # 0.71 insn per cycle (84.29%)
544,411,061 cycles (85.01%)
38,884,991 L1-dcache-load-misses # 32.48% of all L1-dcache hits (85.24%)
119,711,464 L1-dcache-loads (82.94%)
0.192838747 seconds time elapsed
0.200693000 seconds user
0.052919000 seconds sys
```
\ No newline at end of file
......@@ -31,7 +31,7 @@
26,230 cache-misses # 7.882 % of all cache refs (67.17%)
111,702,471 instructions # 1.61 insn per cycle (83.59%)
69,498,357 cycles (83.57%)
** 250,109 L1-dcache-load-misses # 0.43% of all L1-dcache hits (83.58%) **
250,109 L1-dcache-load-misses # 0.43% of all L1-dcache hits (83.58%)
58,115,659 L1-dcache-loads (82.72%)
0.030938059 seconds time elapsed
......@@ -71,51 +71,4 @@
0.158064000 seconds user
1.736704000 seconds sys
```
## 3. Java程序
### a. 编译程序
`javac traverse_1d_array.java`
### b.运行验证
#### 使用array[i][j]遍历数组
`java traverse_1d_array -f`
消耗时间(毫秒):20
#### 使用array[j][i]遍历数组
`java traverse_1d_array -s`
消耗时间(毫秒):100
### c. 使用perf验证缓存命中率
#### 使用array[i][j]遍历数组
`perf stat -e cache-references,cache-misses,instructions,cycles,L1-dcache-load-misses,L1-dcache-loads ./traverse_1d_array -f`
* 输出结果:
```
Performance counter stats for 'java traverse_2d_array -f':
6,379,138 cache-references (80.62%)
866,578 cache-misses # 13.585 % of all cache refs (68.93%)
459,726,039 instructions # 1.51 insn per cycle (85.22%)
303,673,757 cycles (85.69%)
5,270,707 L1-dcache-load-misses # 3.96% of all L1-dcache hits (81.64%)
133,211,743 L1-dcache-loads (83.13%)
0.126089887 seconds time elapsed
0.122353000 seconds user
0.047877000 seconds sys
```
#### 使用array[j][i]遍历数组
`perf stat -e cache-references,cache-misses,instructions,cycles,L1-dcache-load-misses,L1-dcache-loads ./traverse_1d_array -s`
* 输出结果:
```
Performance counter stats for 'java traverse_2d_array -s':
42,441,956 cache-references (80.21%)
872,336 cache-misses # 2.055 % of all cache refs (66.61%)
386,326,280 instructions # 0.71 insn per cycle (84.29%)
544,411,061 cycles (85.01%)
38,884,991 L1-dcache-load-misses # 32.48% of all L1-dcache hits (85.24%)
119,711,464 L1-dcache-loads (82.94%)
0.192838747 seconds time elapsed
0.200693000 seconds user
0.052919000 seconds sys
```
\ No newline at end of file
import java.util.Date;
public class traverse_1d_array{
public static void main(String args[]){
int ch;
int TESTN = 4096;
boolean slowMode = false;
for (String arg : args) {
if ("-f".equals(arg)) {
slowMode = false;
break;
} else if ("-s".equals(arg)) {
slowMode = true;
break;
}
}
char [][]arr = new char[TESTN][TESTN];
Date start = new Date();
if (!slowMode) {
for(int i = 0; i < TESTN; i++) {
for(int j = 0; j < TESTN; j++) {
//arr[i][j]是连续访问的
arr[i][j] = 0;
}
}
} else {
for(int i = 0; i < TESTN; i++) {
for(int j = 0; j < TESTN; j++) {
//arr[j][i]是不连续访问的
arr[j][i] = 0;
}
}
}
System.out.println(new Date().getTime()-start.getTime());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册