mirror of
https://github.com/python/cpython.git
synced 2025-09-28 03:13:48 +00:00
Windows time_clock(): rewrite to get rid of horrid casting tricks.
Don't blame Mark! The horrid casting tricks were my idea to begin with. The rewrite works fine under VC6, and I *expect* will work fine under VC7.
This commit is contained in:
parent
246debbbc2
commit
9ad4b688ec
1 changed files with 10 additions and 12 deletions
|
@ -147,28 +147,26 @@ time_clock(PyObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
time_clock(PyObject *self, PyObject *args)
|
time_clock(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
static LONG_LONG ctrStart;
|
static LARGE_INTEGER ctrStart;
|
||||||
static double divisor = 0.0;
|
static double divisor = 0.0;
|
||||||
LONG_LONG now;
|
LARGE_INTEGER now;
|
||||||
double diff;
|
double diff;
|
||||||
|
|
||||||
assert(sizeof(LONG_LONG) == sizeof(LARGE_INTEGER));
|
|
||||||
if (!PyArg_ParseTuple(args, ":clock"))
|
if (!PyArg_ParseTuple(args, ":clock"))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (divisor == 0.0) {
|
if (divisor == 0.0) {
|
||||||
LONG_LONG freq;
|
LARGE_INTEGER freq;
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*)&ctrStart);
|
QueryPerformanceCounter(&ctrStart);
|
||||||
if (!QueryPerformanceFrequency((LARGE_INTEGER*)&freq) ||
|
if (!QueryPerformanceFrequency(&freq) || freq.QuadPart == 0) {
|
||||||
freq == 0) {
|
|
||||||
/* Unlikely to happen - this works on all intel
|
/* Unlikely to happen - this works on all intel
|
||||||
machines at least! Revert to clock() */
|
machines at least! Revert to clock() */
|
||||||
return PyFloat_FromDouble(clock());
|
return PyFloat_FromDouble(clock());
|
||||||
}
|
}
|
||||||
divisor = (double)freq;
|
divisor = (double)freq.QuadPart;
|
||||||
}
|
}
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*)&now);
|
QueryPerformanceCounter(&now);
|
||||||
diff = (double)(now - ctrStart);
|
diff = (double)(now.QuadPart - ctrStart.QuadPart);
|
||||||
return PyFloat_FromDouble(diff / divisor);
|
return PyFloat_FromDouble(diff / divisor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue