版本比较
DEEPSEEK的人机测试
正文
增加 41 行删除 41 行
12343456788 行未改动1718192021212223242523242526272829293031323320 行未改动545556575858596061623 行未改动6667686970707172737419 行未改动94959697989910010110210398991001011021031041051061071081091101101111121121131141151166 行未改动1231241251261271271281291301316 行未改动1381391401411421421431441451466 行未改动15315415515615715715815916016110 行未改动17217317417517617617717817918017 行未改动19819920020120220220320420520610 行未改动21721821922022122122222322422510 行未改动2362372382392402402412422422432442452462462472482492502492502512522532532542552562572582592602612622632642652662602612622632642652662672682692692702712722732742732742752762772782792802802812822832847 行未改动2922932942952962962972982993002 行未改动```cpp// cpu_benchmark_no_warmup.cpp// ¼òµ¥Ö±½ÓµÄCPUÐÔÄܲâÊÔ£¨ÎÞÔ¤ÈÈ£¬²»¿¨¶Ù£©// ±àÒë: g++ -O2 -std=c++11 -pthread cpu_benchmark_no_warmup.cpp -o cpu_benchmark.exe// 简单直接的CPU性能测试(无预热,不卡顿)// 编译: g++ -O2 -std=c++11 -pthread cpu_benchmark_no_warmup.cpp -o cpu_benchmark.exe
#include <iostream>#include <chrono>#include <vector>8 行未改动#include <atomic>#include <functional>#include <windows.h>
// ==================== ÅäÖòÎÊý ====================// ==================== 配置参数 ====================namespace Config { const int REPEAT_COUNT = 20; // ÖØ¸´´ÎÊý const int ITERATIONS = 50000000; // µü´ú´ÎÊý const int MATRIX_SIZE = 256; // ¾ØÕó´óС const int REPEAT_COUNT = 20; // 重复次数 const int ITERATIONS = 50000000; // 迭代次数 const int MATRIX_SIZE = 256; // 矩阵大小 const int FLOPS_ITERATIONS = 20000000;}
// ==================== CPUÐÅÏ¢ ====================// ==================== CPU信息 ====================class CPUInfo {public: static int get_core_count() { SYSTEM_INFO sysInfo;20 行未改动 return model; }};
// ==================== ¼ÆÊ±Æ÷ ====================// ==================== 计时器 ====================class Timer {public: void start() { m_start = std::chrono::high_resolution_clock::now(); } void stop() { m_end = std::chrono::high_resolution_clock::now(); }3 行未改动private: std::chrono::high_resolution_clock::time_point m_start, m_end;};
// ==================== ²âÊÔÌ×¼þ ====================// ==================== 测试套件 ====================class CPUBenchmark {private: std::vector<double> m_results; std::mutex m_mutex;19 行未改动 double cv = (stddev / mean) * 100.0; std::cout << "\n" << name << ":\n"; std::cout << " ƽ¾ù: " << std::fixed << std::setprecision(2) << mean << " ms\n"; std::cout << " ×îС: " << sorted.front() << " ms\n"; std::cout << " ×î´ó: " << sorted.back() << " ms\n"; std::cout << " ±ê×¼²î: " << stddev << " ms\n"; std::cout << " ±äÒìϵÊý: " << cv << "%"; if (cv < 3.0) std::cout << " ¡ï"; std::cout << " 平均: " << std::fixed << std::setprecision(2) << mean << " ms\n"; std::cout << " 最小: " << sorted.front() << " ms\n"; std::cout << " 最大: " << sorted.back() << " ms\n"; std::cout << " 标准差: " << stddev << " ms\n"; std::cout << " 变异系数: " << cv << "%"; if (cv < 3.0) std::cout << " ★"; std::cout << "\n"; } const std::vector<double>& get_results() const { return m_results; }};
// ==================== ²âÊÔº¯Êý ====================// ==================== 测试函数 ====================
// 1. ÕûÊýÔËËã// 1. 整数运算double test_integer_ops(int iterations) { Timer timer; volatile int result = 0; 6 行未改动 timer.stop(); return timer.elapsed_ms();}
// 2. ¸¡µãÔËËã// 2. 浮点运算double test_float_ops(int iterations) { Timer timer; volatile float result = 1.0f; 6 行未改动 timer.stop(); return timer.elapsed_ms();}
// 3. Ë«¾«¶È¸¡µã// 3. 双精度浮点double test_double_ops(int iterations) { Timer timer; volatile double result = 1.0; 6 行未改动 timer.stop(); return timer.elapsed_ms();}
// 4. ÄÚ´æ´ø¿í// 4. 内存带宽double test_memory_bandwidth() { const int size = 20 * 1024 * 1024 / sizeof(int); std::vector<int> data(size); volatile long long sum = 0;10 行未改动 timer.stop(); return timer.elapsed_ms();}
// 5. ¾ØÕó³Ë·¨// 5. 矩阵乘法double test_matrix_multiply() { const int size = Config::MATRIX_SIZE; std::vector<double> A(size * size); std::vector<double> B(size * size);17 行未改动 timer.stop(); return timer.elapsed_ms();}
// 6. ËØÊý¼ÆËã// 6. 素数计算double test_prime_calculation() { const int max_num = 500000; std::vector<bool> is_prime(max_num + 1, true); is_prime[0] = is_prime[1] = false;10 行未改动 timer.stop(); return timer.elapsed_ms();}
// 7. ÅÅÐò// 7. 排序double test_sorting() { const int size = 100000; std::vector<int> data(size); std::random_device rd;10 行未改动 timer.stop(); return timer.elapsed_ms();}
// ==================== Ö÷³ÌÐò ====================// ==================== 主程序 ====================int main() { // ÉèÖÿØÖÆÌ¨±àÂë // 设置控制台编码 SetConsoleOutputCP(936); std::cout << "\n" << std::string(60, '=') << "\n"; std::cout << " CPUÐÔÄܲâÊÔ (ÎÞÔ¤ÈȰæ)\n"; std::cout << " CPU性能测试 (无预热版)\n"; std::cout << std::string(60, '=') << "\n"; std::cout << "CPU: " << CPUInfo::get_cpu_model() << "\n"; std::cout << "ºËÐÄÊý: " << CPUInfo::get_core_count() << "\n"; std::cout << "ÖØ¸´´ÎÊý: " << Config::REPEAT_COUNT << "\n"; std::cout << "核心数: " << CPUInfo::get_core_count() << "\n"; std::cout << "重复次数: " << Config::REPEAT_COUNT << "\n"; std::cout << std::string(60, '=') << "\n"; // ²âÊÔÅäÖà // 测试配置 struct TestConfig { std::string name; std::function<double()> func; }; std::vector<TestConfig> tests = { {"ÕûÊýÔËËã", []() { return test_integer_ops(Config::ITERATIONS); }}, {"µ¥¾«¶È¸¡µã", []() { return test_float_ops(Config::FLOPS_ITERATIONS); }}, {"Ë«¾«¶È¸¡µã", []() { return test_double_ops(Config::FLOPS_ITERATIONS); }}, {"ÄÚ´æ´ø¿í", []() { return test_memory_bandwidth(); }}, {"¾ØÕó³Ë·¨", []() { return test_matrix_multiply(); }}, {"ËØÊý¼ÆËã", []() { return test_prime_calculation(); }}, {"ÅÅÐòËã·¨", []() { return test_sorting(); }} {"整数运算", []() { return test_integer_ops(Config::ITERATIONS); }}, {"单精度浮点", []() { return test_float_ops(Config::FLOPS_ITERATIONS); }}, {"双精度浮点", []() { return test_double_ops(Config::FLOPS_ITERATIONS); }}, {"内存带宽", []() { return test_memory_bandwidth(); }}, {"矩阵乘法", []() { return test_matrix_multiply(); }}, {"素数计算", []() { return test_prime_calculation(); }}, {"排序算法", []() { return test_sorting(); }} }; // ÔËÐÐËùÓвâÊÔ // 运行所有测试 for (auto& test : tests) { CPUBenchmark benchmark; std::cout << "\n²âÊÔ: " << test.name << "\n"; std::cout << " ÔËÐÐ " << Config::REPEAT_COUNT << " ´Î...\n"; std::cout << "\n测试: " << test.name << "\n"; std::cout << " 运行 " << Config::REPEAT_COUNT << " 次...\n"; for (int i = 0; i < Config::REPEAT_COUNT; ++i) { double result = test.func(); benchmark.add_result(result); // ½ø¶ÈÌõ // 进度条 int progress = (i + 1) * 40 / Config::REPEAT_COUNT; std::cout << "\r [" << std::string(progress, '#') << std::string(40 - progress, ' ') << "] " << (i+1) << "/" << Config::REPEAT_COUNT 7 行未改动 benchmark.print_statistics(test.name); } std::cout << "\n" << std::string(60, '=') << "\n"; std::cout << "²âÊÔÍê³É!\n"; std::cout << "测试完成!\n"; std::cout << std::string(60, '=') << "\n"; system("pause"); return 0;2 行未改动