2017q1 Homework1(phonebook)
contributed by < potinglee
>
Reviewed by yachiyang01
-git commit message需用命令語氣,內文與標題需一個空白行
Reviewed by harryoooooooooo
- C/C++標準中,free(), delete等函式不須再另外判斷是否為NULL,傳入NULL並不會發生錯誤
注意一致的格式 "jserv"
進度嚴重落後,請趕工!課程助教
開發環境
- OS: Ubuntu 16.04.2 LTS
- L1d cache: 32K
- L1i cache: 32K
- L2 cache: 256K
- L3 cache: 6144K
- Architecture: x86_64
- CPU 作業模式: 32-bit, 64-bit
- Byte Order: Little Endian
- CPU(s): 4
- Model name: Intel® Core™ i5-6300HQ CPU @ 2.30GHz
- memory
description: System memory
physical id: 0
size: 7872MiB
未優化版本
- 執行:
$ ./phonebook_orig
- append() 及 findName() 時間如下
- catch test:
$ make cache-test
優化版本1 - 減少資料結構大小
原本的資料結構為:
因為只搜尋 lastName,所以把其他不會用到的成員移除。結果如下:
- 執行:
$ ./phonebook_opt
- append() 及 findName() 時間如下
- catch test:
$ make cache-test
- 和未優化版本的比較圖:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
優化版本2 - 使用二元搜尋樹
將原本的用 linked list 建立的資料,改用二元搜尋樹建立。
原本建立 linked list 的程式:
建立二元搜尋樹的程式:
搜尋二元搜尋樹的 findName():
- 執行:
$ ./phonebook_opt
- append() 及 findName() 時間如下
- catch test:
$ make cache-test
- cache-misses 減少為 68%,但因資料結構較大的緣故,cache-miss較優化版本1增加 5%。
- 和未優化版本的比較圖:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
雖然使用了二元搜尋樹,但 findNmae()的時間卻沒減少,反而增加。
推測是由於每次加新資料都從 tree 的尾端,因此會形成這種狀況:
每一個 node 雖有兩個指標,實際上卻只用到一個(另一個指向 NULL),因此整個二元搜尋樹等同於普通的 linked list,而無法發揮二元搜尋樹的優勢。
請及早調整輸入的 data set "jserv"
優化版本3 - 用樹旋轉改進以上的問題
(working)
可以先將 words.txt 透過 -R 打亂排序
課程助教