Вопрос

Есть ли способ прочитать счетчик временной техники на процессорах x86 в Python?

Я знаю, что использование rdtscp плохо и использование rdtsc еще хуже.Но поверьте мне, мне действительно нужно это значение или, по крайней мере, некоторое приближение этого значения.

Любые идеи?

Это было полезно?

Решение

With normal python, time.clock() is the most accurate thing you will get.

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.

If you really want to have processor ticks, just remember the time which is needed to execute this python call - so Python is not the right language to do microsecond time measurement.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top