UnixBench 簡介
UnixBench (原 BYTE Unix Benchmark) 是類 Unix 系統標準基準測試套件,測試 CPU、記憶體、I/O、管道、進程、Shell、系統呼叫、2D/3D 圖形等多維度效能,輸出單核/多核分數與綜合指數,**跨平台比較參考價值高**。
測試項目詳細解析
| 測試項目 | 測試重點 | 影響因素 |
| Dhrystone 2 (整數運算) | 字串處理、整數運算、編譯器優化、記憶體快取 | CPU 單核效能、編譯器、優化等級 |
| Whetstone (浮點運算) | 浮點運算效率 (sin, cos, sqrt, exp, log) | FPU 效能、向量化指令集 (AVX/SSE) |
| Execl Throughput | exec() 系統呼叫吞吐 (進程建立/映像替換) | 檔案系統、VFS、記憶體管理、核心調度 |
| File Copy (1024/256/4096 bufsize) | 檔案讀/寫/複製吞吐 (不同緩衝區大小) | 儲存子系統、頁面快取、檔案系統 |
| Pipe Throughput | 管道讀寫 512 bytes 循環次數 | 核心管道實作、記憶體複製效率 |
| Pipe-based Context Switching | 兩進程透過管道交換資料的上下文切換率 | 排程器、上下文切換開銷、CPU 緩存親和性 |
| Process Creation | fork()+exit 循環建立子進程速率 | 記憶體管理、複製寫入 (COW)、排程器 |
| Shell Scripts (1/8 concurrent) | 並發 Shell 腳本啟動/停止速率 | Shell 解析器、檔案系統、進程建立 |
| System Call Overhead | getpid() 系統呼叫進入/離開核心開銷 | 系統呼叫進入路徑、VDSO、Spectre/Meltdown 緩解影響 |
| 2D/3D Graphics (ubgears) | 基本 OpenGL 渲染幀率 | GPU 驅動、Mesa、虛擬化 GPU 透傳 |
安裝與執行
# 下載 (官方 GitHub)
wget https://github.com/kdlucas/byte-unixbench/archive/refs/tags/v5.1.3.tar.gz
tar xzf v5.1.3.tar.gz
cd byte-unixbench-5.1.3/UnixBench
# 若無圖形環境/不需圖形測試,註解 Makefile
# GRAPHIC_TESTS = defined
# 編譯
make
# 執行完整測試 (單核 + 多核,約 10-30 分鐘)
./Run
結果解讀範例
==========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)
System: myserver: GNU/Linux
OS: GNU/Linux -- 5.15.0-91-generic -- #101-Ubuntu SMP
Machine: x86_64 (x86_64)
CPU 0: Intel Xeon Platinum 8375C @ 2.90GHz (5800.0 bogomips)
...
Benchmark Run: 三 1月 10 2024 10:00:00 - 10:30:00
1 CPU in system; running 1 parallel copy of tests
Dhrystone 2 using register variables 42000000.0 lps (10.0 s, 7 samples)
Double-Precision Whetstone 5200.0 MWIPS (9.0 s, 7 samples)
Execl Throughput 5800.0 lps (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks 1500000.0 KBps (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks 400000.0 KBps (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks 3200000.0 KBps (30.0 s, 2 samples)
Pipe Throughput 2500000.0 lps (10.0 s, 7 samples)
Pipe-based Context Switching 500000.0 lps (10.0 s, 7 samples)
Process Creation 20000.0 lps (30.0 s, 2 samples)
Shell Scripts (1 concurrent) 8500.0 lpm (60.0 s, 2 samples)
Shell Scripts (8 concurrent) 1200.0 lpm (60.0 s, 2 samples)
System Call Overhead 3200000.0 lps (10.0 s, 7 samples)
System Benchmarks Index Values BASELINE RESULT INDEX
Dhrystone 2 using register variables 116700.0 42000000.0 3599.0
Double-Precision Whetstone 55.0 5200.0 945.5
Execl Throughput 43.0 5800.0 1348.8
File Copy 1024 bufsize 2000 maxblocks 3960.0 1500000.0 3787.9
File Copy 256 bufsize 500 maxblocks 1655.0 400000.0 2416.9
File Copy 4096 bufsize 8000 maxblocks 5800.0 3200000.0 5517.2
Pipe Throughput 12440.0 2500000.0 2009.6
Pipe-based Context Switching 4000.0 500000.0 1250.0
Process Creation 126.0 20000.0 1587.3
Shell Scripts (1 concurrent) 42.4 8500.0 2004.7
Shell Scripts (8 concurrent) 6.0 1200.0 2000.0
System Call Overhead 15000.0 3200000.0 2133.3
========
System Benchmarks Index Score 2156.4
分數解讀關鍵點
- Index 分數:該項目相對基準分 (基準機為 SPARCstation 20-61,定義為 10.0)
- System Benchmarks Index Score:所有項目幾何平均數,**綜合效能指標**
- Single vs Multi Core:報告會輸出 1 份單核、N 份多核 (N=CPU 核心數) 結果
- 對比參考:
- 現代伺服器級 CPU 單核分數通常 1500-3000+
- 桌面級 CPU 單核 2000-4000+
- 虛擬機受限於宿主機排程、CPU 就緒時間,分數通常較低
影響分數的關鍵因素
| 因素 | 影響程度 | 說明 |
| CPU 架構/代數/主頻 | 極高 | 直接決定 Dhrystone/Whetstone/Context Switch 分數 |
| 記憶體頻率/延遲 | 高 | 影響 File Copy、Pipe、Process Creation |
| 儲存子系統 (NVMe/SSD/HDD) | 高 | File Copy 項目極敏感 |
| 編譯器版本/優化參數 | 中高 | GCC 版本、-O2/-O3、-march=native 影響大 |
| 核心版本/調度器 | 中 | CFS 調度、mitigations 影響 System Call/Context Switch |
| 虛擬化開銷 | 高 | CPU Ready 時間、Hypervisor 排程、virtio vs 模擬裝置 |
| 背景負載 | 中 | 測試期間避免其他負載干擾 |
進階用法
# 僅執行特定測試
./Run dhry2reg whetstone-double syscall
# 指定並行數 (覆蓋預設 CPU 核心數)
./Run -c 4
# 只跑單核測試
./Run -1
# 自定義輸出目錄
./Run -d /tmp/bench_results
# 針對雲端實例對比:相同編譯環境、相同參數、多次取中位數
替代/補充工具
- Phoronix Test Suite:更豐富測試集、Web 介面、自動化比較
- Geekbench 6:跨平台 (含手機/ARM)、單/多核、GPU Compute
- sysbench:模組化 (CPU/記憶體/檔案 I/O/線程/互斥鎖/資料庫 OLTP)
- fio:儲存效能專業測試 (IOPS、延遲、頻寬、一致性)
- iperf3:網路頻寬/抖動/丟包測試