2

寻找最准确的时间戳。

看来 CPU 周期计数器可以提供: using unsigned __int64 __rdtsc();

如果我能够关闭动态 CPU 速度选项,英特尔芯片上的“SpeedStep 技术”(来自我假设的 BIOS?):

  • rdtsc() 是否会准确测量两个事件之间经过的时间?

  • cpu时钟速度是多少?是否正是宣传的 CPU 速度(即 2.4 GHz CPU - 每秒使用 2,400,000,000 来划分 CPU 时钟计数值以获得实际时间)?

4

1 回答 1

2

Will rdtsc() be an accurate measure of elapsed time between two events?

No, not generally. It might stand some chance if you restricted the code to run on a single processor/core, but without that, differences between the counters to the separate processors/cores can lead to erroneous results.

What will be the cpu clock speed? Is it be exactly the advertised CPU speed (i.e. 2.4 GHz CPU - use 2,400,000,000 per second to divide the CPU clock count value for getting the actual time)?

Most machines allow the user to adjust the clock speed in the BIOS setup. Depending on the environment in which your code is running you may have access to the motherboard's 1.024 MHz clock, which is constant regardless of CPU clock speed. If you can read it, that can give you a solid basis for determining the rate you're getting on the time-stamp counter.

于 2013-11-12T01:04:30.490 回答