blob: 4e10e31349040baa04881be63996c3cd13e254d4 [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
Thomas Woutersf3f33dc2000-07-21 06:00:07 +000055DL_EXPORT(void) inittiming(void)
Guido van Rossum116857c1994-01-02 23:22:21 +000056{
Barry Warsaw58d40a71997-01-13 22:57:42 +000057 (void)Py_InitModule("timing", timing_methods);
Guido van Rossum116857c1994-01-02 23:22:21 +000058}