Files
membank/auto-check/pkg/stress/benchmark.go

612 lines
35 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package stress
import (
"fmt"
"strings"
)
// ============================
// 性能/温度基准(让用户对结果有感性认知)
// ============================
//
// 评级说明(与"超过正常"程度绑定4 档):
// - 远低于正常 red #dc2626
// - 达到正常 green #16a34a
// - 超过正常 blue #3b82f6
// - 远超过正常 purple #7c3aed
//
// 评分方向:
// - higher_better: 数值越大越好CPU/内存跑分、IOPS、吞吐
// - lower_better : 数值越小越好(温度)
//
// 阈值Cutoffs3 个分界点将数值划分为 4 档。
// - higher_better: <c0 远低于, c0~c1 正常, c1~c2 超过, ≥c2 远超过
// - lower_better : >c0 远低于(危险), c1~c0 正常, c2~c1 超过, ≤c2 远超过(优秀)
//
// 阈值仅作参考,应根据实际硬件代际持续校准;下文取自常见消费级/主流企业级硬件中位水平。
// Level 评级
type Level string
const (
LevelPoor Level = "poor" // 远低于正常
LevelNormal Level = "normal" // 达到正常
LevelGood Level = "good" // 超过正常
LevelExcellent Level = "excellent" // 远超过正常
)
// LevelDisplay 评级显示元数据
type LevelDisplay struct {
Text string // 远低于正常 / 达到正常 / 超过正常 / 远超过正常
Color string // 颜色(与报告 CSS 协调)
Order int // 0/1/2/3 用于排序与综合评级
}
var levelDisplay = map[Level]LevelDisplay{
LevelPoor: {Text: "远低于正常", Color: "#dc2626", Order: 0},
LevelNormal: {Text: "达到正常", Color: "#16a34a", Order: 1},
LevelGood: {Text: "超过正常", Color: "#3b82f6", Order: 2},
LevelExcellent: {Text: "远超过正常", Color: "#7c3aed", Order: 3},
}
// LevelMeta 取评级显示信息,未知时返回 normal
func LevelMeta(l Level) LevelDisplay {
if d, ok := levelDisplay[l]; ok {
return d
}
return LevelDisplay{Text: string(l), Color: "#64748b", Order: 1}
}
// Direction 评分方向
type Direction string
const (
DirHigherBetter Direction = "higher" // 越高越好
DirLowerBetter Direction = "lower" // 越低越好
)
// MetricBench 单个指标的基准配置
type MetricBench struct {
Key string // 指标键score / max_temp / iops_total / bw_total
Label string // 显示名
Unit string // 单位
Direction Direction // 评分方向
Cutoffs [3]float64
Note string // 备注(用于展示)
}
// ============================
// 各指标基准(消费/主流企业级硬件参考)
// ============================
// CPU 跑分stress-ng bogo ops/s4 线程参考(线程越多分越高)
var benchCPU = MetricBench{
Key: "score", Label: "CPU 跑分", Unit: "ops/s",
Direction: DirHigherBetter,
Cutoffs: [3]float64{8000, 20000, 40000},
Note: "stress-ng bogo ops/s4 线程参考;线程数越多分越高)",
}
// 内存跑分
var benchMemory = MetricBench{
Key: "score", Label: "内存跑分", Unit: "ops/s",
Direction: DirHigherBetter,
Cutoffs: [3]float64{5000, 15000, 30000},
Note: "stress-ng bogo ops/s",
}
// 综合工况CPU+内存 综合
var benchFull = MetricBench{
Key: "score", Label: "综合跑分", Unit: "ops/s",
Direction: DirHigherBetter,
Cutoffs: [3]float64{6000, 18000, 35000},
Note: "CPU+内存综合 ops/s",
}
// 内存精压MB/sDDR4 一般 20-50 GB/s受通道数和频率影响
var benchMemNative = MetricBench{
Key: "score", Label: "内存带宽", Unit: "MB/s",
Direction: DirHigherBetter,
Cutoffs: [3]float64{3000, 8000, 15000},
Note: "内存读写带宽",
}
// 磁盘 4K 随机读写 IOPS
var benchDiskIOPS = MetricBench{
Key: "iops_total", Label: "磁盘 IOPS", Unit: "ops/s",
Direction: DirHigherBetter,
Cutoffs: [3]float64{1000, 10000, 50000},
Note: "4K 随机读写:<1k≈HDD, 1k-10k≈低端 SSD, 10k-50k≈SATA/NVMe 入门, >50k≈NVMe 中高端",
}
// 磁盘读写总带宽
var benchDiskBW = MetricBench{
Key: "bw_total", Label: "磁盘吞吐", Unit: "MB/s",
Direction: DirHigherBetter,
Cutoffs: [3]float64{100, 500, 2000},
Note: "读写总带宽:<100≈HDD, 100-500≈低端 SSD, 500-2000≈SATA/NVMe 入门, >2000≈NVMe Gen3+",
}
// 最高温度°C越低越好
var benchTemp = MetricBench{
Key: "max_temp", Label: "最高温度", Unit: "°C",
Direction: DirLowerBetter,
Cutoffs: [3]float64{90, 75, 60}, // 阈值由高到低poor/normal, normal/good, good/excellent
Note: "<60°C 优秀, 60-75°C 正常, 75-90°C 偏高, >90°C 危险",
}
// ============================
// 硬件基准库(按 CPU 型号匹配)
// ============================
//
// 设计目的:不同代/不同档位的硬件不能用同一套阈值比较。
// 例如 i3 与 i7 跑分差距数倍J4125 与 N100 也不能直接比较。
//
// 使用方式:
// - MatchHardware(cpuModel) 依据 CPU 型号子串匹配(大小写不敏感)
// - 匹配成功 → 使用该硬件的专属阈值评估
// - 未匹配 → 所有指标强制返回 LevelNormal"达到正常"),不判定好坏
// - 库中字段为 nil → 退到默认基准
//
// 维护说明:库按"匹配顺序"查找,越靠前越优先。新增型号请在最匹配的
// 位置追加i5-12xxx 必须在 i5 之前),否则会被更宽泛的规则先匹配。
// HardwareBench 一类硬件的基准
type HardwareBench struct {
// Match CPU 型号匹配子串(大小写不敏感),如 "i7-12"、"N100"、"Ryzen 5"
Match string
// Note 硬件说明,会显示在报告备注里
Note string
// CPU/Memory/Full/MemBand 各类跑分基准nil 表示使用默认基准
CPU *MetricBench
Memory *MetricBench
Full *MetricBench
MemBand *MetricBench
}
// hardwareLibrary 硬件基准库(按匹配顺序查找,越靠前越优先)
// 数值参考stress-ng bogo ops/s @ 默认线程数;内存带宽为 stream/memcpy 估算
// 维护提醒:每代 CPU 阈值约为上一代的 1.15~1.30 倍,跨代需重新校准
var hardwareLibrary = []HardwareBench{
// ============ Intel 飞牛常用低功耗 ============
{
Match: "N100", Note: "Intel N100 (Alder Lake-N, 4C/4T, 6W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 22000, 38000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{5000, 12000, 22000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{8000, 18000, 30000}, Note: "CPU+内存综合"},
MemBand: &MetricBench{Key: "score", Label: "内存带宽", Unit: "MB/s", Direction: DirHigherBetter, Cutoffs: [3]float64{3000, 8000, 15000}, Note: "单通道 DDR5 带宽上限"},
},
{
Match: "N305", Note: "Intel N305 (Alder Lake-N, 8C/8T, 15W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{20000, 40000, 65000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{8000, 18000, 35000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{15000, 30000, 50000}, Note: "CPU+内存综合"},
MemBand: &MetricBench{Key: "score", Label: "内存带宽", Unit: "MB/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4000, 10000, 18000}, Note: "DDR5 双通道带宽"},
},
{
Match: "N95", Note: "Intel N95 (Alder Lake-N, 4C/4T, 15W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 20000, 35000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{5000, 11000, 20000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{8000, 16000, 28000}, Note: "CPU+内存综合"},
MemBand: &MetricBench{Key: "score", Label: "内存带宽", Unit: "MB/s", Direction: DirHigherBetter, Cutoffs: [3]float64{3000, 7000, 13000}, Note: "单通道 DDR4/DDR5 带宽"},
},
{
Match: "N5105", Note: "Intel Celeron N5105 (Jasper Lake, 4C/4T, 10W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{7000, 14000, 25000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4000, 9000, 16000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{5000, 12000, 22000}, Note: "CPU+内存综合"},
},
{
Match: "N5095", Note: "Intel Celeron N5095 (Jasper Lake, 4C/4T, 15W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{6000, 12000, 22000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4000, 8000, 15000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{5000, 10000, 19000}, Note: "CPU+内存综合"},
},
{
Match: "J4125", Note: "Intel Celeron J4125 (Gemini Lake, 4C/4T, 10W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{5000, 10000, 18000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{3000, 6000, 12000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4000, 8000, 15000}, Note: "CPU+内存综合"},
},
{
Match: "J4105", Note: "Intel Celeron J4105 (Gemini Lake, 4C/4T, 10W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4500, 9000, 16000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{3000, 6000, 11000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4000, 7500, 14000}, Note: "CPU+内存综合"},
},
{
Match: "J3455", Note: "Intel Celeron J3455 (Apollo Lake, 4C/4T, 10W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{3500, 7500, 13000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{2500, 5000, 9500}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{3000, 6500, 12000}, Note: "CPU+内存综合"},
},
{
Match: "J1900", Note: "Intel Celeron J1900 (Bay Trail, 4C/4T, 10W)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{2500, 5500, 10000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{2000, 4000, 7000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{2000, 4500, 8500}, Note: "CPU+内存综合"},
},
{
Match: "Celeron", Note: "Intel Celeron (其他型号)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{5000, 12000, 22000}, Note: "Celeron 系列通用参考"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{3000, 7000, 14000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4000, 10000, 18000}, Note: "CPU+内存综合"},
},
{
Match: "Atom", Note: "Intel Atom",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{2000, 5000, 9000}, Note: "Atom 系列通用参考"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{1500, 3500, 6500}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{1800, 4500, 8000}, Note: "CPU+内存综合"},
},
// ============ Intel Core i9按代匹配 ============
{
Match: "i9-13", Note: "13代 i9 (Raptor Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{50000, 100000, 160000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{20000, 50000, 90000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{30000, 70000, 120000}, Note: "CPU+内存综合"},
},
{
Match: "i9-12", Note: "12代 i9 (Alder Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{40000, 85000, 140000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{18000, 45000, 80000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{28000, 60000, 100000}, Note: "CPU+内存综合"},
},
{
Match: "i9-11", Note: "11代 i9 (Rocket Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{35000, 75000, 125000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{15000, 38000, 70000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{25000, 55000, 95000}, Note: "CPU+内存综合"},
},
{
Match: "i9-10", Note: "10代 i9 (Comet Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{30000, 65000, 110000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{14000, 35000, 65000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{22000, 48000, 85000}, Note: "CPU+内存综合"},
},
{
Match: "i9-", Note: "Intel Core i9 (其他代)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{25000, 55000, 95000}, Note: "i9 通用参考"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{12000, 30000, 60000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{20000, 45000, 80000}, Note: "CPU+内存综合"},
},
// ============ Intel Core i7按代匹配 ============
{
Match: "i7-13", Note: "13代 i7 (Raptor Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{40000, 85000, 140000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{18000, 45000, 80000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{28000, 60000, 100000}, Note: "CPU+内存综合"},
},
{
Match: "i7-12", Note: "12代 i7 (Alder Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{32000, 70000, 115000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{16000, 40000, 70000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{24000, 52000, 90000}, Note: "CPU+内存综合"},
},
{
Match: "i7-11", Note: "11代 i7 (Rocket Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{28000, 60000, 100000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{14000, 35000, 60000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{22000, 48000, 80000}, Note: "CPU+内存综合"},
},
{
Match: "i7-10", Note: "10代 i7 (Comet Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{25000, 55000, 90000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{12000, 30000, 55000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{20000, 42000, 72000}, Note: "CPU+内存综合"},
},
{
Match: "i7-8", Note: "8/9代 i7 (Coffee Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{20000, 45000, 75000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 25000, 45000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{16000, 35000, 60000}, Note: "CPU+内存综合"},
},
{
Match: "i7-7", Note: "7代 i7 (Kaby Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{16000, 35000, 60000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{8000, 20000, 38000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{12000, 28000, 48000}, Note: "CPU+内存综合"},
},
{
Match: "i7-", Note: "Intel Core i7 (其他代)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{18000, 40000, 70000}, Note: "i7 通用参考"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{9000, 22000, 42000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{14000, 32000, 55000}, Note: "CPU+内存综合"},
},
// ============ Intel Core i5按代匹配 ============
{
Match: "i5-13", Note: "13代 i5 (Raptor Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{30000, 65000, 105000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{14000, 35000, 60000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{22000, 48000, 80000}, Note: "CPU+内存综合"},
},
{
Match: "i5-12", Note: "12代 i5 (Alder Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{25000, 55000, 90000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{12000, 30000, 55000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{18000, 40000, 70000}, Note: "CPU+内存综合"},
},
{
Match: "i5-11", Note: "11代 i5 (Rocket Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{22000, 48000, 80000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{11000, 27000, 48000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{16000, 35000, 60000}, Note: "CPU+内存综合"},
},
{
Match: "i5-10", Note: "10代 i5 (Comet Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{20000, 42000, 70000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 25000, 45000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{14000, 32000, 55000}, Note: "CPU+内存综合"},
},
{
Match: "i5-8", Note: "8/9代 i5 (Coffee Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{15000, 32000, 55000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{8000, 18000, 35000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 24000, 42000}, Note: "CPU+内存综合"},
},
{
Match: "i5-", Note: "Intel Core i5 (其他代)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{14000, 30000, 50000}, Note: "i5 通用参考"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{7000, 17000, 32000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 22000, 40000}, Note: "CPU+内存综合"},
},
// ============ Intel Core i3按代匹配 ============
{
Match: "i3-13", Note: "13代 i3 (Raptor Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{20000, 42000, 70000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 24000, 45000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{15000, 32000, 55000}, Note: "CPU+内存综合"},
},
{
Match: "i3-12", Note: "12代 i3 (Alder Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{18000, 38000, 62000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{9000, 22000, 40000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{13000, 28000, 50000}, Note: "CPU+内存综合"},
},
{
Match: "i3-10", Note: "10代 i3 (Comet Lake)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{14000, 30000, 50000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{7000, 17000, 32000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 22000, 40000}, Note: "CPU+内存综合"},
},
{
Match: "i3-", Note: "Intel Core i3 (其他代)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 22000, 38000}, Note: "i3 通用参考"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{5500, 13000, 25000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{8000, 18000, 32000}, Note: "CPU+内存综合"},
},
// ============ Intel Xeon ============
{
Match: "Xeon", Note: "Intel Xeon",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{30000, 70000, 120000}, Note: "Xeon 通用参考(按核心数浮动大)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{15000, 35000, 70000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{22000, 50000, 90000}, Note: "CPU+内存综合"},
},
// ============ AMD Ryzen按系列 ============
{
Match: "Ryzen 9", Note: "AMD Ryzen 9",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{40000, 85000, 145000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{18000, 45000, 85000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{30000, 65000, 110000}, Note: "CPU+内存综合"},
},
{
Match: "Ryzen 7", Note: "AMD Ryzen 7",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{28000, 60000, 100000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{13000, 32000, 60000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{20000, 45000, 78000}, Note: "CPU+内存综合"},
},
{
Match: "Ryzen 5", Note: "AMD Ryzen 5",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{22000, 48000, 80000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{11000, 26000, 48000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{16000, 36000, 62000}, Note: "CPU+内存综合"},
},
{
Match: "Ryzen 3", Note: "AMD Ryzen 3",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{14000, 30000, 50000}, Note: "stress-ng bogo ops/s4 线程)"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{7000, 17000, 32000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{10000, 22000, 40000}, Note: "CPU+内存综合"},
},
{
Match: "Athlon", Note: "AMD Athlon",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{5000, 11000, 20000}, Note: "Athlon 通用参考"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{3000, 7000, 13000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4000, 9000, 17000}, Note: "CPU+内存综合"},
},
{
Match: "AMD", Note: "AMD 处理器 (其他型号)",
CPU: &MetricBench{Key: "score", Label: "CPU 跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{8000, 18000, 32000}, Note: "AMD 通用参考"},
Memory: &MetricBench{Key: "score", Label: "内存跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{4000, 10000, 18000}, Note: "stress-ng bogo ops/s"},
Full: &MetricBench{Key: "score", Label: "综合跑分", Unit: "ops/s", Direction: DirHigherBetter, Cutoffs: [3]float64{6000, 14000, 25000}, Note: "CPU+内存综合"},
},
}
// MatchHardware 根据 CPU 型号匹配硬件基准(大小写不敏感,子串匹配)
// 返回 nil 表示未在库中(调用方应将所有指标视为"达到正常",不做好坏判定)
func MatchHardware(cpuModel string) *HardwareBench {
if cpuModel == "" {
return nil
}
lower := strings.ToLower(cpuModel)
for i := range hardwareLibrary {
if strings.Contains(lower, strings.ToLower(hardwareLibrary[i].Match)) {
return &hardwareLibrary[i]
}
}
return nil
}
// ============================
// 评估函数
// ============================
// EvalBench 根据基准评估单个数值
func EvalBench(b MetricBench, value float64) Level {
c := b.Cutoffs
switch b.Direction {
case DirHigherBetter:
switch {
case value < c[0]:
return LevelPoor
case value < c[1]:
return LevelNormal
case value < c[2]:
return LevelGood
default:
return LevelExcellent
}
case DirLowerBetter:
switch {
case value > c[0]:
return LevelPoor
case value > c[1]:
return LevelNormal
case value > c[2]:
return LevelGood
default:
return LevelExcellent
}
}
return LevelNormal
}
// ReferenceText 生成"参考范围"展示文本
func (b MetricBench) ReferenceText() string {
c := b.Cutoffs
if b.Direction == DirHigherBetter {
return fmt.Sprintf(
"参考: <%.0f%s 远低于 · %.0f-%.0f%s 正常 · %.0f-%.0f%s 良好 · ≥%.0f%s 卓越",
c[0], b.Unit, c[0], c[1], b.Unit, c[1], c[2], b.Unit, c[2], b.Unit,
)
}
return fmt.Sprintf(
"参考: >%.0f%s 危险 · %.0f-%.0f%s 偏高 · %.0f-%.0f%s 正常 · ≤%.0f%s 优秀",
c[0], b.Unit, c[1], c[0], b.Unit, c[2], c[1], b.Unit, c[2], b.Unit,
)
}
// BenchItem 一次基准评估的展示单元(序列化到报告)
type BenchItem struct {
Key string `json:"key"`
Label string `json:"label"`
Value string `json:"value"` // 格式化后的值,如 "72.0 °C"
ValueNum float64 `json:"value_num"` // 原始数值
Unit string `json:"unit"`
Level Level `json:"level"`
LevelText string `json:"level_text"`
LevelColor string `json:"level_color"`
Reference string `json:"reference"`
Note string `json:"note"`
}
// OverallLevel 取多个评级中"最差"(最差用于提示风险)
func OverallLevel(items []BenchItem) Level {
if len(items) == 0 {
return ""
}
worst := LevelExcellent
for _, it := range items {
if LevelMeta(it.Level).Order < LevelMeta(worst).Order {
worst = it.Level
}
}
return worst
}
// EvaluateResult 对一个 Result 评估所有可用指标的基准
// 返回的列表按"重要性"排序:跑分 → 温度 → IOPS → 吞吐
// cpuModel: 设备 CPU 型号(来自 sysInfo["cpu"]);空串或不在库中时,所有指标项
// 强制返回 LevelNormal"达到正常"),不做好坏判定,避免误报
func EvaluateResult(r Result, cpuModel string) []BenchItem {
hb := MatchHardware(cpuModel)
inLibrary := hb != nil
var items []BenchItem
makeItem := func(b MetricBench, v float64) BenchItem {
// 未在库中 → 强制 normal已匹配 → 按专属阈值评估
lvl := LevelNormal
if inLibrary {
lvl = EvalBench(b, v)
}
d := LevelMeta(lvl)
return BenchItem{
Key: b.Key,
Label: b.Label,
Value: fmt.Sprintf("%.1f %s", v, b.Unit),
ValueNum: v,
Unit: b.Unit,
Level: lvl,
LevelText: d.Text,
LevelColor: d.Color,
Reference: b.ReferenceText(),
Note: b.Note,
}
}
// pickBench 选基准:库中有专属 → 专属;库中无该字段或未在库 → 默认
pickBench := func(field *MetricBench, defaultBench MetricBench) MetricBench {
if hb != nil && field != nil {
return *field
}
return defaultBench
}
// 1) 跑分(按测试类型选基准)
if r.Score > 0 {
var b MetricBench
switch r.Type {
case TestCPU:
if hb != nil {
b = pickBench(hb.CPU, benchCPU)
} else {
b = benchCPU
}
case TestMemory:
if hb != nil {
b = pickBench(hb.Memory, benchMemory)
} else {
b = benchMemory
}
case TestFull:
if hb != nil {
b = pickBench(hb.Full, benchFull)
} else {
b = benchFull
}
case TestMemNative:
if hb != nil {
b = pickBench(hb.MemBand, benchMemNative)
} else {
b = benchMemNative
}
}
if b.Key != "" {
items = append(items, makeItem(b, r.Score))
}
}
// 2) 温度max_temp 存在即评估)
// 温度阈值为通用参考60/75/90°C未在库中同样会按通用阈值评估并强制 normal
if t, ok := r.Metrics["max_temp"]; ok && t > 0 {
items = append(items, makeItem(benchTemp, t))
}
// 3) 磁盘 IOPS通用参考与 CPU 无关)
if t, ok := r.Metrics["iops_total"]; ok && t > 0 {
items = append(items, makeItem(benchDiskIOPS, t))
}
// 4) 磁盘吞吐(通用参考,与 CPU 无关)
if t, ok := r.Metrics["bw_total"]; ok && t > 0 {
items = append(items, makeItem(benchDiskBW, t))
}
return items
}