/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. #include "Python.h"
  5. /* Our stuff... */
  6. #include "timing.h"
  7. static PyObject *
  8. start_timing(PyObject *self)
  9. {
  10. Py_INCREF(Py_None);
  11. BEGINTIMING;
  12. return Py_None;
  13. }
  14. static PyObject *
  15. finish_timing(PyObject *self)
  16. {
  17. ENDTIMING
  18. Py_INCREF(Py_None);
  19. return Py_None;
  20. }
  21. static PyObject *
  22. seconds(PyObject *self)
  23. {
  24. return PyInt_FromLong(TIMINGS);
  25. }
  26. static PyObject *
  27. milli(PyObject *self)
  28. {
  29. return PyInt_FromLong(TIMINGMS);
  30. }
  31. static PyObject *
  32. micro(PyObject *self)
  33. {
  34. return PyInt_FromLong(TIMINGUS);
  35. }
  36. static PyMethodDef timing_methods[] = {
  37. {"start", (PyCFunction)start_timing, METH_NOARGS},
  38. {"finish", (PyCFunction)finish_timing, METH_NOARGS},
  39. {"seconds", (PyCFunction)seconds, METH_NOARGS},
  40. {"milli", (PyCFunction)milli, METH_NOARGS},
  41. {"micro", (PyCFunction)micro, METH_NOARGS},
  42. {NULL, NULL}
  43. };
  44. PyMODINIT_FUNC inittiming(void)
  45. {
  46. if (PyErr_WarnPy3k("the timing module has been removed in "
  47. "Python 3.0; use time.clock() instead", 2) < 0)
  48. return;
  49. (void)Py_InitModule("timing", timing_methods);
  50. }