From: W. Trevor King Date: Wed, 17 Apr 2013 16:07:19 +0000 (-0400) Subject: spammify.c: Require a certain count instead of elapsed time X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=438984c44ae396ed60ba66172b941c0b997bf2f0;p=cpython-extension.git spammify.c: Require a certain count instead of elapsed time Increasing the number of threads time sharing on the same core does not increase total execution time if the threads are only checking for elapsed time. We need them to actually *do* something. --- diff --git a/spammify.c b/spammify.c index 1001f34..2482e66 100644 --- a/spammify.c +++ b/spammify.c @@ -1,27 +1,23 @@ #include #include -#include static PyObject * spam_busy(PyObject *self, PyObject *args) { - int seconds; - time_t start; - long int i = 0; + long int count, i; - if (!PyArg_ParseTuple(args, "i", &seconds)) + if (!PyArg_ParseTuple(args, "l", &count)) return NULL; Py_BEGIN_ALLOW_THREADS - start = time(NULL); - while (time(NULL) < start + seconds) - i++; + for (i = 0; i < count; i++) + ; Py_END_ALLOW_THREADS return PyLong_FromLong(i); } static PyMethodDef SpamMethods[] = { {"busy", spam_busy, METH_VARARGS, - "Drop the GIL and run a busy wait for a few seconds."}, + "Drop the GIL and run a busy wait until you count to `count`."}, {NULL, NULL, 0, NULL} /* Sentinel */ };