From 438984c44ae396ed60ba66172b941c0b997bf2f0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 17 Apr 2013 12:07:19 -0400 Subject: [PATCH] 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. --- spammify.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) 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 */ }; -- 2.26.2