#include <iostream>
#include <chrono>
// 获取当前CPU的时钟周期数
unsigned long long getCycleCount() {
unsigned int hi, lo;
__asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi));
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
}
int main() {
// 记录程序开始时间点
auto start = std::chrono::high_resolution_clock::now();
// 执行需要测量时间的代码段
// 这里可以是任何需要测量时间的代码
// 记录程序结束时间点
auto end = std::chrono::high_resolution_clock::now();
// 计算程序在当前CPU上的实际运行时间
std::chrono::duration<double> duration = end - start;
double current_cpu_time_taken = duration.count();
// 假设目标CPU的时钟频率为3.5 GHz(这里只是一个示例,请替换为实际的目标CPU频率)
double target_cpu_frequency = 3.5e9; // 目标CPU频率为3.5 GHz
// 根据目标CPU频率估算在目标CPU上的运行时间
double estimated_time_on_target_cpu = current_cpu_time_taken * (target_cpu_frequency / getCycleCount());
// 输出估算的目标CPU上的运行时间,单位秒
std::cout << "估算的目标CPU上的运行时间:" << estimated_time_on_target_cpu << " 秒\n";
return 0;
}
04-08
4667
03-31
4652