}
static PyMethodDef pakfireModuleMethods[] = {
- {"performance_index", (PyCFunction)performance_index, METH_VARARGS, NULL},
{"native_arch", (PyCFunction)_pakfire_native_arch, METH_NOARGS, NULL },
{"supported_arches", (PyCFunction)_pakfire_supported_arches, METH_NOARGS, NULL },
{ NULL, NULL, 0, NULL }
#include <datetime.h>
#include <errno.h>
-#include <time.h>
-#include <unistd.h>
#include <pakfire/filelist.h>
#include <pakfire/package.h>
#include "package.h"
#include "util.h"
-static unsigned long fibonnacci(const clock_t* deadline) {
- clock_t now = clock();
-
- unsigned long f1 = 1;
- unsigned long f2 = 1;
-
- // Count iterations
- unsigned long counter = 0;
-
- while (now < *deadline) {
- unsigned long next = f1 + f2;
- f1 = f2;
- f2 = next;
-
- now = clock();
- counter++;
- }
-
- return counter;
-}
-
-PyObject* performance_index(PyObject* self, PyObject* args) {
- int seconds = 1;
-
- if (!PyArg_ParseTuple(args, "|i", &seconds)) {
- return NULL;
- }
-
- if (seconds == 0) {
- PyErr_SetString(PyExc_ValueError, "Runtime must be one second or longer");
- return NULL;
- }
-
- // Determine the number of online processors
- int processors = sysconf(_SC_NPROCESSORS_ONLN);
-
- // Determine deadline
- clock_t deadline = clock();
- deadline += CLOCKS_PER_SEC * seconds;
-
- // Run Fibonnacci until deadline
- unsigned long iterations = fibonnacci(&deadline);
-
- // Times the result by the number of processors
- iterations *= processors;
-
- // Normalise to a second
- iterations /= seconds;
-
- return PyLong_FromUnsignedLong(iterations);
-}
-
PyObject* PyList_FromPackageList(struct pakfire_packagelist* packagelist) {
PyObject* list = PyList_New(0);
#include <pakfire/filelist.h>
#include <pakfire/packagelist.h>
-extern PyObject* performance_index(PyObject* self, PyObject* args);
-
PyObject* PyList_FromPackageList(struct pakfire_packagelist* packagelist);
PyObject* PyList_FromFileList(struct pakfire_filelist* filelist);