2022q1 Homework3 (fibdrv)
contributed by <huang-me
>
排除干擾效能分析的因素
-
抑制 address space layout randomization (ASLR)
-
設定 scaling_governor 為 performance。準備以下 shell script,檔名為 performance.sh
:
之後再用 $ sudo sh performance.sh
執行
-
針對 Intel 處理器,關閉 turbo mode
Fix variable-length array in fib_sequence
- 因為永遠只需要前兩項的值,因此其實不需要這麼多記憶體位置記錄所有之前計算的值。
fast doubling
利用 F(n) 以及 F(n+1) 直接計算 F(2n) 之值。
- 原本使用 iterative 的方式計算 Fibonacci number 的時間複雜度爲 O(n) 的時間複雜度。
- 使用 fast doubling 因為無論 n 的大小都只需要做計算32次,因此只需要 O(1) 的時間複雜度。
效能分析
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 →
滿足前面推論的 O(n) 以及 O(1),不過因為需要 shift 太多次,所以在 F(40) 以前並沒有任何的優勢。
fast doubling with clz
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 →
因為大幅減少了前面無意義的 shift,也大幅的減少了計算所需的時間。