contributed by <ryanpatiency
>
changyuanhua
Cache:
Intel® Core™ i5-4210U CPU @ 1.70GHz × 4
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
linux kernel:
$ uname -a
Linux 4.4.0-62-generic
作業要求 B01: phonebook
append()
和findName()
的執行時間findName()
的執行時間,並使append()
的執行時間不增加太多觀察 Makefile ,發現:
make phonebook_orig
來 compile phonebook_orig ,其中的-DIMPL $@.h
目的是用來指定 Micro IMPL 的值make run
來執行程式,其中echo 3 | sudo tee /proc/sys/vm/drop_caches
功能可見這裡,make cache-test
,會重覆執行 orig 和 opt 各一百次,將結果寫進 orig.txt 和 opt.txt,記錄四個 event: cache-misses,cache-references,instructions,cycles ,印出結果make plot
畫圖,會執行 cache-test ,並畫圖findName()
和append()
的執行時間:size of entry : 136 bytes
execution time of append() : 0.068975 sec
execution time of findName() : 0.006140 sec
其中append()
是用來將 DICT_FILE (這裡是./dictionary/words.txt) 建立成資料結構(這裡是linked list),而findName()
是用來在此資料結構尋找含一名字的節點
Performance counter stats for './phonebook_orig' (100 runs):
1,260,786 cache-misses # 88.433 % of all cache refs ( +- 0.43% )
1,425,695 cache-references ( +- 0.36% )
261,104,813 instructions # 1.35 insns per cycle ( +- 0.02% )
194,024,625 cycles ( +- 0.47% )
0.076814845 seconds time elapsed ( +- 0.62% )
重複共筆demo中的優化版本 1 的實驗
Performance counter stats for './phonebook_opt' (100 runs):
153,395 cache-misses # 29.770 % of all cache refs ( +- 0.86% )
515,261 cache-references ( +- 1.02% )
244,213,713 instructions # 1.63 insns per cycle ( +- 0.02% )
149,662,137 cycles ( +- 1.04% )
0.062095272 seconds time elapsed ( +- 1.40% )
可見 cache miss 從 88% 減為 30%
findName()
的執行時間從 0.006255 減為 0.002870 (s)Q1. 有代表性嗎?跟真實英文姓氏差異大嗎?
Ans: words.txt 中的名字前五個分別是:
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa
我覺得沒有代表性,與真實名字差異很多。
Q2. 資料難道「數大就是美」嗎?
Ans:
Q3. 如果我們要建立符合真實電話簿情境的輸入,該怎麼作?
Ans: