是否有正确的功能基准测试方法

Is there the right way of function benchmarking?

本文关键字:功能 基准 测试方法 是否      更新时间:2023-10-16

我想问,哪种测量函数执行所需时间的方法被认为是最好的?只是好奇。谢谢

您可以尝试使用rdtsc();它是准确的,也许是最快的,跨平台的(但仅适用于x86体系结构)。例如,在Windows:中

#include <intrin.h>
uint64_t rdtsc()
{
return __rdtsc();
}