#include <iostream>
#include <windows.h>
#include <vector>
#include <fstream>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
// 获取CPU核心数量
int getCpuCore()
{
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
}
// 获取总物理内存(GB)
double getTotalRam()
{
MEMORYSTATUSEX memInfo;
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo);
return memInfo.ullTotalPhys / 1024.0 / 1024 / 1024;
}
// CPU跑分:3秒浮点运算,最高35分
double testCpuScore(int testTime = 3)
{
clock_t start = clock();
long long operateCount = 0;
double temp = 0;
while ((clock() - start) / CLOCKS_PER_SEC < testTime)
{
for (int i = 0; i < 50000; i++)
{
temp += sin(i) * cos(sqrt(i + 0.5));
operateCount++;
}
}
double score = operateCount / 800000.0 * 35.0;
return min(score, 35.0);
}
// 磁盘读写跑分,最高35分(修复string兼容报错)
double testDiskScore()
{
const string tempFileName = "benchmark_temp.tmp";
const int fileSize = 20 * 1024 * 1024; // 20MB测试文件
vector<char> buffer(fileSize, 0xAA);
// 写入测速
clock_t writeStart = clock();
ofstream writeFile(tempFileName.c_str(), ios::binary);
writeFile.write(buffer.data(), fileSize);
writeFile.close();
double writeSecond = (clock() - writeStart) / (double)CLOCKS_PER_SEC;
double writeSpeed = 20.0 / writeSecond;
// 读取测速
clock_t readStart = clock();
ifstream readFile(tempFileName.c_str(), ios::binary);
readFile.read(buffer.data(), fileSize);
readFile.close();
double readSecond = (clock() - readStart) / (double)CLOCKS_PER_SEC;
double readSpeed = 20.0 / readSecond;
// 删除临时文件
remove(tempFileName.c_str());
double avgSpeed = (writeSpeed + readSpeed) / 2.0;
double score = avgSpeed / 800.0 * 35.0;
return min(score, 35.0);
}
// 内存容量得分,最高30分
double testRamScore(double totalGB)
{
double score = totalGB / 64.0 * 30.0;
return min(score, 30.0);
}
int main()
{
system("chcp 65001 > nul");
SetConsoleOutputCP(65001);
cout << "======== Windows设备综合跑分工具 ========\n\n";
int cpuCore = getCpuCore();
double ramGB = getTotalRam();
cout << "CPU核心数:" << cpuCore << endl;
cout.precision(4);
cout << "整机物理内存:" << ramGB << " GB\n\n";
cout << "【1/3】正在CPU**能测试(3秒)..." << endl;
double cpuScore = testCpuScore();
cout.precision(5);
cout << "CPU分项分数(上限35):" << cpuScore << "\n\n";
cout << "【2/3】正在磁盘读写测速..." << endl;
double diskScore = testDiskScore();
cout << "磁盘分项分数(上限35):" << diskScore << "\n\n";
cout << "【3/3】内存容量评分完成" << endl;
double ramScore = testRamScore(ramGB);
cout << "内存分项分数(上限30):" << ramScore << "\n\n";
double totalScore = cpuScore + diskScore + ramScore;
cout << "========================================" << endl;
cout << " 设备综合总分:" << totalScore << " / 100" << endl;
cout << "========================================" << endl;
cout << "设备评级:";
if (totalScore >= 85)
cout << "高端游戏主机,大型游戏、剪辑无压力";
else if (totalScore >= 65)
cout << "中端主机,网游、日常软件流畅运行";
else if (totalScore >= 40)
cout << "办公主机,适合网课、文档、看视频";
else
cout << "老旧低配设备,多开软件容易卡顿"; cout << "\n\n按回车键退出程序...";
system("pause");
return 0;
}
//========================================
// �豸�ۺ��ܷ֣�69.302 / 100 <--满分100,得了69.302分
//========================================
//弹出乱码解法,如上注释
