home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / py2s152.zip / Modules / timingmodule.c < prev    next >
C/C++ Source or Header  |  1999-06-27  |  1KB  |  88 lines

  1. /*
  2.  * Author: George V. Neville-Neil
  3.  */
  4.  
  5. #include "Python.h"
  6.  
  7. /* Our stuff... */
  8. #include "timing.h"
  9.  
  10. static PyObject *
  11. start_timing(self, args)
  12.     PyObject *self;
  13.     PyObject *args;
  14. {
  15.     if (!PyArg_Parse(args, ""))
  16.         return NULL;
  17.  
  18.     Py_INCREF(Py_None);
  19.     BEGINTIMING;
  20.     return Py_None;
  21. }
  22.  
  23. static PyObject *
  24. finish_timing(self, args)
  25.     PyObject *self;
  26.     PyObject *args;
  27. {
  28.     if (!PyArg_Parse(args, ""))
  29.         return NULL;
  30.  
  31.     ENDTIMING    
  32.     Py_INCREF(Py_None);
  33.     return Py_None;
  34. }
  35.  
  36. static PyObject *
  37. seconds(self, args)
  38.     PyObject *self;
  39.     PyObject *args;
  40. {
  41.     if (!PyArg_Parse(args, ""))
  42.         return NULL;
  43.  
  44.     return PyInt_FromLong(TIMINGS);
  45.  
  46. }
  47.  
  48. static PyObject *
  49. milli(self, args)
  50.     PyObject *self;
  51.     PyObject *args;
  52. {
  53.     if (!PyArg_Parse(args, ""))
  54.         return NULL;
  55.  
  56.     return PyInt_FromLong(TIMINGMS);
  57.  
  58. }
  59. static PyObject *
  60. micro(self, args)
  61.     PyObject *self;
  62.     PyObject *args;
  63. {
  64.     if (!PyArg_Parse(args, ""))
  65.         return NULL;
  66.  
  67.     return PyInt_FromLong(TIMINGUS);
  68.  
  69. }
  70.  
  71.  
  72. static PyMethodDef timing_methods[] = {
  73.     {"start",   start_timing},
  74.     {"finish",  finish_timing},
  75.     {"seconds", seconds},
  76.     {"milli",   milli},
  77.     {"micro",   micro},
  78.     {NULL,      NULL}
  79. };
  80.  
  81.  
  82. DL_EXPORT(void) inittiming()
  83. {
  84.     (void)Py_InitModule("timing", timing_methods);
  85.     if (PyErr_Occurred())
  86.         Py_FatalError("can't initialize module timing");
  87. }
  88.