python - 在Python中读取rdtsc

标签 python rdtsc

有没有办法在 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/

相关文章:

python - 不平衡面板数据 : How to use Time Series Splits Cross-Validation?

python - 在 Python 中以毫秒频率生成时间戳

linux - 时间戳计数器

c++ - 在具有 constant_tsc 和 nonstop_tsc 的 cpu 上,为什么我的时间会漂移?

c - 跨上下文切换使用 rdtsc + rdtscp

python - 如何在列表理解中使用重新匹配对象

Python - 将日期的字符串表示形式转换为 ISO 8601

python - pygame Sprite 似乎拉伸(stretch)/增长而不是沿 x 轴移动

profiling - 如何检测 RDTSC 是否返回恒定速率计数器值?

c++ - "rdtsc": "=a" (a0), "=d"(d0) 这是做什么的?