PageRenderTime 38ms CodeModel.GetById 18ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

/Modules/timingmodule.c

http://unladen-swallow.googlecode.com/
C | 62 lines | 46 code | 12 blank | 4 comment | 1 complexity | 4631d251cbfddcf81f3ab50044675d72 MD5 | raw file
 1/*
 2 * Author: George V. Neville-Neil
 3 */
 4
 5#include "Python.h"
 6
 7/* Our stuff... */
 8#include "timing.h"
 9
10static PyObject *
11start_timing(PyObject *self)
12{
13	Py_INCREF(Py_None);
14	BEGINTIMING;
15	return Py_None;
16}
17
18static PyObject *
19finish_timing(PyObject *self)
20{
21	ENDTIMING    
22	Py_INCREF(Py_None);
23	return Py_None;
24}
25
26static PyObject *
27seconds(PyObject *self)
28{
29	return PyInt_FromLong(TIMINGS);
30}
31
32static PyObject *
33milli(PyObject *self)
34{
35	return PyInt_FromLong(TIMINGMS);
36}
37
38static PyObject *
39micro(PyObject *self)
40{
41	return PyInt_FromLong(TIMINGUS);
42}
43
44
45static PyMethodDef timing_methods[] = {
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},
51	{NULL,      NULL}
52};
53
54
55PyMODINIT_FUNC inittiming(void)
56{
57    if (PyErr_WarnPy3k("the timing module has been removed in "
58                        "Python 3.0; use time.clock() instead", 2) < 0)
59        return;
60    
61	(void)Py_InitModule("timing", timing_methods);
62}