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 * |
Neal Norwitz | 50905b5 | 2002-03-31 14:57:24 +0000 | [diff] [blame] | 11 | start_timing(PyObject *self) |
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 | Py_INCREF(Py_None); |
| 14 | BEGINTIMING; |
| 15 | return Py_None; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 16 | } |
| 17 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 18 | static PyObject * |
Neal Norwitz | 50905b5 | 2002-03-31 14:57:24 +0000 | [diff] [blame] | 19 | finish_timing(PyObject *self) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 20 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 21 | ENDTIMING |
| 22 | Py_INCREF(Py_None); |
| 23 | return Py_None; |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 26 | static PyObject * |
Neal Norwitz | 50905b5 | 2002-03-31 14:57:24 +0000 | [diff] [blame] | 27 | seconds(PyObject *self) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 28 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 29 | return PyInt_FromLong(TIMINGS); |
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 * |
Neal Norwitz | 50905b5 | 2002-03-31 14:57:24 +0000 | [diff] [blame] | 33 | milli(PyObject *self) |
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 | return PyInt_FromLong(TIMINGMS); |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 36 | } |
Neal Norwitz | 50905b5 | 2002-03-31 14:57:24 +0000 | [diff] [blame] | 37 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 38 | static PyObject * |
Neal Norwitz | 50905b5 | 2002-03-31 14:57:24 +0000 | [diff] [blame] | 39 | micro(PyObject *self) |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 40 | { |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 41 | return PyInt_FromLong(TIMINGUS); |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 45 | static PyMethodDef timing_methods[] = { |
Neal Norwitz | 50905b5 | 2002-03-31 14:57:24 +0000 | [diff] [blame] | 46 | {"start", (PyCFunction)start_timing, METH_NOARGS}, |
| 47 | {"finish", (PyCFunction)finish_timing, METH_NOARGS}, |
| 48 | {"seconds", (PyCFunction)seconds, METH_NOARGS}, |
| 49 | {"milli", (PyCFunction)milli, METH_NOARGS}, |
| 50 | {"micro", (PyCFunction)micro, METH_NOARGS}, |
Barry Warsaw | 58d40a7 | 1997-01-13 22:57:42 +0000 | [diff] [blame] | 51 | {NULL, NULL} |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 55 | DL_EXPORT(void) inittiming(void) |
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 | (void)Py_InitModule("timing", timing_methods); |
Guido van Rossum | 116857c | 1994-01-02 23:22:21 +0000 | [diff] [blame] | 58 | } |