最近我试图测量cpu缩放的效果。如果我用这个时钟测量它,它是否准确?
template<std::intmax_t clock_freq>
struct rdtsc_clock {
typedef unsigned long long rep;
typedef std::ratio<1, clock_freq> period;
typedef std::chrono::duration<rep, period> duration;
typedef std::chrono::time_point<rdtsc_clock> time_point;
static const bool is_steady = true;
static time_point now() noexcept
{
unsigned lo, hi;
asm volatile("rdtsc" : "=a" (lo), "=d" (hi));
return time_point(duration(static_cast<rep>(hi) << 32 | lo));
}
};
更新:
根据我的另一个post的评论,我相信redtsc不能用来衡量cpu频率缩放的效果,因为来自redtsc的计数器不受CPU频率的影响,我是对的吗?