# 2016q3 Homework 1 (phonebook)
## 環境
**ubuntu 14.04 32-bit**
建立與win7的雙系統
* win7 -> 開始 -> 電腦「右鍵」 -> 管理 -> 磁碟管理
* 將D槽壓縮(壓縮大小代表要free出來的空間)
* NTFS 為 windows 的磁碟空間,ETX4 為 的壓縮空間
## 熟悉效能分析工具Perf
## 熟悉Github
* 產生SSH key
* 執行以下 ->
```shell
$ echo "# phonebook" >> README.md`
$ git status # 顯示有被更改的檔案
$ git add . # 加上所有被更改的檔案
$ git commit # 第1段描述, 之後詳述1. 2. 3. .....
$ git push # 放到Github上,
```
> 玉青教學[name="游玉青"]
## 程式最佳化
* 還未最佳化的成果圖:

```
* Performance counter stats for './phonebook_opt' (100 runs):
4,316,065 cache-misses # 97.887 % of all cache refs (51.73%)
4,764,991 cache-references (54.90%)
311,493,843 instructions # 1.56 insns per cycle (52.17%)
191,701,079 cycles (22.74%)
0.054593797 seconds time elapsed ( +- 0.23% )
```
* 修改phonebook_opt.h的struct,只留下lastname、next

>>> 這圖片輸入的數值是錯的,請檢查 [name=jserv]
>>> 更正過了[name=shou cheng]
* 將資料結構做簡化
```
* Performance counter stats for './phonebook_opt' (100 runs):
845,098 cache-misses # 47.218 % of all cache refs (52.74%)
1,771,599 cache-references (55.44%)
252,165,094 instructions # 1.87 insns per cycle (50.23%)
136,732,509 cycles (22.64%)
0.036402972 seconds time elapsed ( +- 0.28% )
( +- 0.26% )
```
* 遇到的第一個字母與比較的字母不相同則略過迴圈

```
* Performance counter stats for './phonebook_opt' (100 runs):
1,088,834 cache-misses # 65.712 % of all cache refs (51.37%)
1,890,934 cache-references (51.64%)
212,738,900 instructions # 1.80 insns per cycle (49.37%)
119,314,552 cycles (25.79%)
0.033524031 seconds time elapsed ( +- 0.26% )
```
1. 主要修改phonebook_opt.c & phonebook_opt.h
2. cache miss、
3. 對程式碼做編排
>main.c 通常只有一個(好的程式)[name=jersv]