在本地執行基準測試
我們有一個簡單的工作流程,用於執行 SunSpider、Kraken 和 Octane 的「傳統」基準測試。你可以使用不同的二進位檔和旗標組合執行,結果會根據多次執行取平均值。
CPU #
按照 使用 GN 建置中的說明建置 d8
shell。
在執行基準測試之前,請務必將 CPU 頻率調整設定為效能。
sudo tools/cpu.sh fast
cpu.sh
了解的指令為
fast
、效能(fast
的別名)slow
、省電(slow
的別名)default
、隨需應變(default
的別名)dualcore
(停用所有核心,僅保留兩個核心)、雙核心(dualcore
的別名)allcores
(重新啟用所有可用核心)、全部核心(allcores
的別名)。
CSuite #
CSuite
是我們簡單的基準測試執行器
test/benchmarks/csuite/csuite.py
(sunspider | kraken | octane)
(baseline | compare)
<path to d8 binary>
[-x "<optional extra d8 command-line flags>"]
首先以 baseline
模式執行,建立基準線,然後以 compare
模式執行,取得結果。CSuite
預設對 Octane 執行 10 次、對 SunSpider 執行 100 次、對 Kraken 執行 80 次,但你可以使用 -r
選項覆寫這些設定,以取得更快的結果。
CSuite
會在你執行的目錄中建立兩個子目錄
./_benchmark_runner_data
— 這是 N 次執行的快取輸出。./_results
— 它會將結果寫入此處的主控檔中。你可以將這些
檔案儲存為不同的名稱,它們會顯示在比較模式中。
在比較模式中,你自然會使用不同的二進位檔或至少不同的旗標。
範例用法 #
假設你已經建置了兩個版本的 d8
,並想看看 SunSpider 會發生什麼事。首先,建立基準線
$ test/benchmarks/csuite/csuite.py sunspider baseline out.gn/master/d8
Wrote ./_results/master.
Run sunspider again with compare mode to see results.
如建議,再次執行,但這次以 compare
模式執行,並使用不同的二進位檔
$ test/benchmarks/csuite/csuite.py sunspider compare out.gn/x64.release/d8
benchmark: score | master | % |
===================================================+==========+========+
3d-cube-sunspider: 13.9 S 13.4 S -3.6 |
3d-morph-sunspider: 8.6 S 8.4 S -2.3 |
3d-raytrace-sunspider: 15.1 S 14.9 S -1.3 |
access-binary-trees-sunspider: 3.7 S 3.9 S 5.4 |
access-fannkuch-sunspider: 11.9 S 11.8 S -0.8 |
access-nbody-sunspider: 4.6 S 4.8 S 4.3 |
access-nsieve-sunspider: 8.4 S 8.1 S -3.6 |
bitops-3bit-bits-in-byte-sunspider: 2.0 | 2.0 | |
bitops-bits-in-byte-sunspider: 3.7 S 3.9 S 5.4 |
bitops-bitwise-and-sunspider: 2.7 S 2.9 S 7.4 |
bitops-nsieve-bits-sunspider: 5.3 S 5.6 S 5.7 |
controlflow-recursive-sunspider: 3.8 S 3.6 S -5.3 |
crypto-aes-sunspider: 10.9 S 9.8 S -10.1 |
crypto-md5-sunspider: 7.0 | 7.4 S 5.7 |
crypto-sha1-sunspider: 9.2 S 9.0 S -2.2 |
date-format-tofte-sunspider: 9.8 S 9.9 S 1.0 |
date-format-xparb-sunspider: 10.3 S 10.3 S |
math-cordic-sunspider: 6.1 S 6.2 S 1.6 |
math-partial-sums-sunspider: 20.2 S 20.1 S -0.5 |
math-spectral-norm-sunspider: 3.2 S 3.0 S -6.2 |
regexp-dna-sunspider: 7.6 S 7.8 S 2.6 |
string-base64-sunspider: 14.2 S 14.0 | -1.4 |
string-fasta-sunspider: 12.8 S 12.6 S -1.6 |
string-tagcloud-sunspider: 18.2 S 18.2 S |
string-unpack-code-sunspider: 20.0 | 20.1 S 0.5 |
string-validate-input-sunspider: 9.4 S 9.4 S |
SunSpider: 242.6 S 241.1 S -0.6 |
---------------------------------------------------+----------+--------+
前一次執行的輸出會快取在目前目錄中建立的子目錄(_benchmark_runner_data
)中。總計結果也會快取在目錄 _results
中。執行比較步驟後,可以刪除這些目錄。
另一種情況是你有相同的二進位檔,但想查看不同旗標的結果。感覺有點好笑,你想看看 Octane 在沒有最佳化編譯器的情況下會如何執行。首先是基準線
$ test/benchmarks/csuite/csuite.py -r 1 octane baseline out.gn/x64.release/d8
Normally, octane requires 10 runs to get stable results.
Wrote /usr/local/google/home/mvstanton/src/v8/_results/master.
Run octane again with compare mode to see results.
請注意警告,通常一次執行不足以確定許多效能最佳化,但是,我們的「變更」應該只執行一次就會產生可重製的效果!現在讓我們比較,傳遞 --noopt
旗標來關閉 TurboFan
$ test/benchmarks/csuite/csuite.py -r 1 octane compare out.gn/x64.release/d8 \
-x "--noopt"
Normally, octane requires 10 runs to get stable results.
benchmark: score | master | % |
===================================================+==========+========+
Richards: 973.0 | 26770.0 | -96.4 |
DeltaBlue: 1070.0 | 57245.0 | -98.1 |
Crypto: 923.0 | 32550.0 | -97.2 |
RayTrace: 2896.0 | 75035.0 | -96.1 |
EarleyBoyer: 4363.0 | 42779.0 | -89.8 |
RegExp: 2881.0 | 6611.0 | -56.4 |
Splay: 4241.0 | 19489.0 | -78.2 |
SplayLatency: 14094.0 | 57192.0 | -75.4 |
NavierStokes: 1308.0 | 39208.0 | -96.7 |
PdfJS: 6385.0 | 26645.0 | -76.0 |
Mandreel: 709.0 | 33166.0 | -97.9 |
MandreelLatency: 5407.0 | 97749.0 | -94.5 |
Gameboy: 5440.0 | 54336.0 | -90.0 |
CodeLoad: 25631.0 | 25282.0 | 1.4 |
Box2D: 3288.0 | 67572.0 | -95.1 |
zlib: 59154.0 | 58775.0 | 0.6 |
Typescript: 12700.0 | 23310.0 | -45.5 |
Octane: 4070.0 | 37234.0 | -89.1 |
---------------------------------------------------+----------+--------+
很酷,可以看到 CodeLoad
和 zlib
相對不受影響。
深入探討 #
CSuite
是基於同一個目錄中的兩個指令碼,benchmark.py
和 compare-baseline.py
。這些指令碼中有更多選項。例如,你可以記錄多個基準線,並進行 3、4 或 5 向比較。CSuite
經過最佳化,可快速使用,並犧牲了一些彈性。