有没有办法在 Python 中读取 x86 CPU 上的时间戳计数器?
我知道使用 rdtscp
不好,使用 rdtsc
更糟糕。但请相信我,我确实需要该值,或者至少是该值的近似值。
有什么想法吗?
最佳答案
对于普通的Python,time.clock()是你能得到的最准确的东西。
time.clock()
On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the same name, but in any case, this is the function to use for benchmarking Python or timing algorithms.
On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.
如果您确实想要处理器滴答声,只需记住执行此 python 调用所需的时间 - 因此 Python 不是进行微秒时间测量的正确语言。
关于python - 在Python中读取rdtsc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9020134/