# 2016q3 Homework1(phonebook)
### Reviewed by `believe7028`
- 可以對 perf 所量測得到的信息做說明更細緻的解釋,以及是否有其他事件數據可說明程式的狀況。
- 除了縮小資料結構的大小,可以採用如雜湊等方法增加搜尋的效能。
- 如果未來資料一直增長,Linked list 可能無法在記憶體放所有資料。
- 可以加入刪除的功能以符合實際的需求。
- git log message 可以更明確指出做了什麼動作(mody xxx),並且增加細部的說明(the xxx ... because ...),讓開頭主題簡潔明確。
## 開發環境
* Linux核心:Linux version 3.19.0-25-generic
## 準備工作
* [Lubuntu](http://lubuntu.net/)
* 雙螢幕設定:終端機輸入
```shell
sudo apt-get update # 更新套件庫
sudo apt-get install disper # 安裝disper
disper -d auto -e -t right # 向右延伸桌面
```
* 使用LVPM擴充Lubuntu佔用的空間,改用新的root.disk檔重新開機後出現以下提示
```
[Minimal BASH-like line editing is supported. for the first word,
TAB lists possible command completions. Anywhere else TABlists
the possible completions of a device/filename.]
grub>
```
換回舊的root.disk檔 能正常開機 Lubuntu在C槽中所站空間的確依照空間提昇
但Lubuntu系統能使用的空間依然為括充前的容量
* github
* 生成 SSH 公開金鑰: 成大wiki相關參考資料的step 6中提到的指令無法生成SSH Key
改成以下指令即可
```
$ cat ~/.ssh/id_rsa.pub
```
* 練習

* clone 從別人那裡fork來的專案 不用init,skip step.4
* clone 下來的不用remote ,skip step.11,直接輸入 git push
* 參考資料
* [參考資料:藉由 Disper 自動切換延伸桌面](http://ericcubelifetw.blogspot.tw/2013/06/lubuntu.html)
* [伺服器上的 Git - 生成 SSH 公開金鑰](https://git-scm.com/book/zh-tw/v1/%E4%BC%BA%E6%9C%8D%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E7%94%9F%E6%88%90-SSH-%E5%85%AC%E9%96%8B%E9%87%91%E9%91%B0)
* [使用Git與Github管理軟體開發專案](http://billy3321.blogspot.tw/2009/02/github-howto.html)
* [LVPM把wubi版的Ubuntu硬碟容量變大了 ](http://mypaper.pchome.com.tw/coldswallo/post/1311135584)
* [連猴子都能懂的Git入門指南](https://backlogtool.com/git-guide/tw/)
* git練習流程圖---by我妹妹
## 原始版本
* 執行結果
```
size of entry : 136 bytes
execution time of append() : 0.077054 sec
execution time of findName() : 0.006564 sec
3
```
* Perf 檢視catch miss
```
$ make cache-test
```
* 結果
```
Performance counter stats for './phonebook_orig' (100 runs):
1,986,847 cache-misses # 89.834 % of all cache refs ( +- 0.11% )
2,211,677 cache-references ( +- 0.12% )
262,179,442 instructions # 1.35 insns per cycle ( +- 0.02% )
194,202,618 cycles ( +- 0.33% )
0.090345079 seconds time elapsed ( +- 0.97% )
```

## 方法一:改變結構,使entry size變小
* 從phonebook中搜尋資料 以lastname作為索引 所以所以一開始 cache中有lastname即可
不需要將所有細節資料全部載入
```clike=
typedef struct __LAST_NAME_ENTRY {
char lastName[MAX_LAST_NAME_SIZE];
__PHONE_BOOK_DETAIL *pDetail;
struct __LAST_NAME_ENTRY *pNext;
} entry;
```
* 執行結果
```
size of entry : 32 bytes
execution time of append() : 0.068336 sec
execution time of findName() : 0.003898 sec
3
```
* Perf檢視cache miss
```
$ make cache-test
```
```
Performance counter stats for './phonebook_opt' (100 runs):
334,859 cache-misses # 58.245 % of all cache refs ( +- 0.26% )
574,913 cache-references ( +- 0.31% )
245,984,198 instructions # 1.73 insns per cycle ( +- 0.02% )
142,449,286 cycles ( +- 0.14% )
0.071604653 seconds time elapsed ( +- 0.97% )
```

>> 這圖片是錯的!沒反映程式執行時間的變化,請改正 [name=jserv]
>> 將 `phonebook_opt.h` 中的 `#define OPT1` 註解取消掉 , 因為實驗室電腦lubuntu系統被我玩壞了 ,所以改成用別台電腦的 linux mint 作業系統做作業,謝謝老師在作業上的提點
[name=LitSnow]
* 參考資料
* [呂紹榕同學的詳細檔案分析與程式碼註解](https://hackmd.io/CYJgZgHA7AnADAFgLQGMCmaCGSEGYCsyMARjPkgIwhS4gT4VwogJA===?view#)
* [老師的作業說明](https://hackmd.io/s/S1RVdgza)
* [書籍:由片語學習C程式設計---劉邦鋒 著]
* [phonebook中的Makefile]