blob: 0da5c6b763d771db7dcd276bbb3ae2075860d02e [file] [log] [blame]
Guido van Rossum116857c1994-01-02 23:22:21 +00001/*
Guido van Rossum116857c1994-01-02 23:22:21 +00002 * Author: George V. Neville-Neil
Guido van Rossum116857c1994-01-02 23:22:21 +00003 */
4
Barry Warsaw58d40a71997-01-13 22:57:42 +00005#include "Python.h"
Guido van Rossum116857c1994-01-02 23:22:21 +00006
7/* Our stuff... */
8#include "timing.h"
9
Barry Warsaw58d40a71997-01-13 22:57:42 +000010static PyObject *
Neal Norwitz50905b52002-03-31 14:57:24 +000011start_timing(PyObject *self)
Guido van Rossum116857c1994-01-02 23:22:21 +000012{
Barry Warsaw58d40a71997-01-13 22:57:42 +000013 Py_INCREF(Py_None);
14 BEGINTIMING;
15 return Py_None;
Guido van Rossum116857c1994-01-02 23:22:21 +000016}
17
Barry Warsaw58d40a71997-01-13 22:57:42 +000018static PyObject *
Neal Norwitz50905b52002-03-31 14:57:24 +000019finish_timing(PyObject *self)
Guido van Rossum116857c1994-01-02 23:22:21 +000020{
Barry Warsaw58d40a71997-01-13 22:57:42 +000021 ENDTIMING
22 Py_INCREF(Py_None);
23 return Py_None;
Guido van Rossum116857c1994-01-02 23:22:21 +000024}
25
Barry Warsaw58d40a71997-01-13 22:57:42 +000026static PyObject *
Neal Norwitz50905b52002-03-31 14:57:24 +000027seconds(PyObject *self)
Guido van Rossum116857c1994-01-02 23:22:21 +000028{
Barry Warsaw58d40a71997-01-13 22:57:42 +000029 return PyInt_FromLong(TIMINGS);
Guido van Rossum116857c1994-01-02 23:22:21 +000030}
31
Barry Warsaw58d40a71997-01-13 22:57:42 +000032static PyObject *
Neal Norwitz50905b52002-03-31 14:57:24 +000033milli(PyObject *self)
Guido van Rossum116857c1994-01-02 23:22:21 +000034{
Barry Warsaw58d40a71997-01-13 22:57:42 +000035 return PyInt_FromLong(TIMINGMS);
Guido van Rossum116857c1994-01-02 23:22:21 +000036}
Neal Norwitz50905b52002-03-31 14:57:24 +000037
Barry Warsaw58d40a71997-01-13 22:57:42 +000038static PyObject *
Neal Norwitz50905b52002-03-31 14:57:24 +000039micro(PyObject *self)
Guido van Rossum116857c1994-01-02 23:22:21 +000040{
Barry Warsaw58d40a71997-01-13 22:57:42 +000041 return PyInt_FromLong(TIMINGUS);
Guido van Rossum116857c1994-01-02 23:22:21 +000042}
43
44
Barry Warsaw58d40a71997-01-13 22:57:42 +000045static PyMethodDef timing_methods[] = {
Neal Norwitz50905b52002-03-31 14:57:24 +000046 {"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 Warsaw58d40a71997-01-13 22:57:42 +000051 {NULL, NULL}
Guido van Rossum116857c1994-01-02 23:22:21 +000052};
53
54
Mark Hammondfe51c6d2002-08-02 02:27:13 +000055PyMODINIT_FUNC inittiming(void)
Guido van Rossum116857c1994-01-02 23:22:21 +000056{
Brett Cannonbb141bb2008-05-12 03:47:47 +000057 if (PyErr_WarnPy3k("the timing module has been removed in "
58 "Python 3.0; use time.clock() instead", 2) < 0)
59 return;
60
Barry Warsaw58d40a71997-01-13 22:57:42 +000061 (void)Py_InitModule("timing", timing_methods);
Guido van Rossum116857c1994-01-02 23:22:21 +000062}