Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 1 | /* |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 2 | * Author: George V. Neville-Neil |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 3 | */ |
| 4 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 5 | #include "Python.h" |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 6 | |
| 7 | /* Our stuff... */ |
| 8 | #include "timing.h" |
| 9 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 10 | static PyObject * |
Peter Schneider-Kamp | e89b156 | 2000-07-10 12:04:18 +0000 | [diff] [blame] | 11 | start_timing(PyObject *self, PyObject *args) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 12 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 13 | if (!PyArg_Parse(args, "")) |
| 14 | return NULL; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 15 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 16 | Py_INCREF(Py_None); |
| 17 | BEGINTIMING; |
| 18 | return Py_None; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 21 | static PyObject * |
Peter Schneider-Kamp | e89b156 | 2000-07-10 12:04:18 +0000 | [diff] [blame] | 22 | finish_timing(PyObject *self, PyObject *args) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 23 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 24 | if (!PyArg_Parse(args, "")) |
| 25 | return NULL; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 26 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 27 | ENDTIMING |
| 28 | Py_INCREF(Py_None); |
| 29 | return Py_None; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 32 | static PyObject * |
Peter Schneider-Kamp | e89b156 | 2000-07-10 12:04:18 +0000 | [diff] [blame] | 33 | seconds(PyObject *self, PyObject *args) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 34 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 35 | if (!PyArg_Parse(args, "")) |
| 36 | return NULL; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 37 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 38 | return PyInt_FromLong(TIMINGS); |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 39 | |
| 40 | } |
| 41 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 42 | static PyObject * |
Peter Schneider-Kamp | e89b156 | 2000-07-10 12:04:18 +0000 | [diff] [blame] | 43 | milli(PyObject *self, PyObject *args) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 44 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 45 | if (!PyArg_Parse(args, "")) |
| 46 | return NULL; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 47 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 48 | return PyInt_FromLong(TIMINGMS); |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 49 | |
| 50 | } |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 51 | static PyObject * |
Peter Schneider-Kamp | e89b156 | 2000-07-10 12:04:18 +0000 | [diff] [blame] | 52 | micro(PyObject *self, PyObject *args) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 53 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 54 | if (!PyArg_Parse(args, "")) |
| 55 | return NULL; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 56 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 57 | return PyInt_FromLong(TIMINGUS); |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 58 | |
| 59 | } |
| 60 | |
| 61 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 62 | static PyMethodDef timing_methods[] = { |
| 63 | {"start", start_timing}, |
| 64 | {"finish", finish_timing}, |
| 65 | {"seconds", seconds}, |
| 66 | {"milli", milli}, |
| 67 | {"micro", micro}, |
| 68 | {NULL, NULL} |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 72 | DL_EXPORT(void) inittiming(void) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 73 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 74 | (void)Py_InitModule("timing", timing_methods); |
| 75 | if (PyErr_Occurred()) |
| 76 | Py_FatalError("can't initialize module timing"); |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 77 | } |