[issue37205] time.perf_counter() is not system-wide on Windows, in disagreement with documentation
Daniel Hrisca
report at bugs.python.org
Fri Nov 13 14:36:46 EST 2020
Daniel Hrisca <daniel.hrisca at gmail.com> added the comment:
I'm actually surprised that this problem gets so little interest. It's probably so obscure that most people don't even realize it.
Why isn't it implemented using winapi calls for the windows platform?
I took inspiration from this SO thread https://stackoverflow.com/questions/56502111/should-time-perf-counter-be-consistent-across-processes-in-python-on-windows
and came up with this function for 64 bit Python (a few more lines would be needed for error checking)
#include <windows.h>
static PyObject* perf_counter(PyObject* self, PyObject* args)
{
PyObject* ret;
QueryPerformanceFrequency(lpFrequency);
QueryPerformanceCounter(lpPerformanceCount);
ret = PyFloat_FromDouble(((double) lpPerformanceCount->QuadPart ) / lpFrequency->QuadPart);
return ret;
}
----------
nosy: +danielhrisca
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37205>
_______________________________________
More information about the Python-bugs-list
mailing list