NEURON
ftime.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include "hoc.h"
3 
4 #if defined(HAVE_GETTIMEOFDAY)
5 
6 #include <sys/time.h>
7 static double start_time = 0.;
8 
9 #else
10 
11 #include <time.h>
12 static time_t start_time = 0; /* time_t is a long */
13 static time_t stop_time = 1;
14 
15 #endif
16 
17 #define Ret(a) \
18  hoc_ret(); \
19  hoc_pushx(a);
20 
21 double nrn_time(void) {
22 #if defined(HAVE_GETTIMEOFDAY)
23  int ms10;
24  struct timeval x;
25  gettimeofday(&x, (struct timezone*) 0);
26  ms10 = x.tv_usec / 10000;
27  start_time = (100. * (double) (x.tv_sec) + (double) ms10) / 100.;
28  return (start_time);
29 #else
30  return ((double) time(&start_time));
31 #endif
32 }
33 
34 
35 void hoc_startsw(void) {
36  Ret(nrn_time());
37 }
38 
39 void hoc_stopsw(void) {
40 #if defined(HAVE_GETTIMEOFDAY)
41  double y;
42  int ms10;
43  struct timeval x;
44  gettimeofday(&x, (struct timezone*) 0);
45  ms10 = x.tv_usec / 10000;
46  y = (double) (x.tv_sec) + (double) ms10 / 100.;
47  Ret(y - start_time);
48  start_time = y;
49 #else
50  if (start_time == 0) {
51  Printf("Must use startsw() first.\n");
52  Ret(0.);
53  } else {
54  time(&stop_time);
55  Ret((double) (stop_time - start_time));
56  }
57 #endif
58 }
59 
60 
61 double nrn_timeus(void) {
62 #if defined(HAVE_GETTIMEOFDAY)
63  struct timeval x;
64  gettimeofday(&x, (struct timezone*) 0);
65  return ((double) x.tv_sec + .000001 * ((double) x.tv_usec));
66 #else
67  return 0.;
68 #endif
69 }
#define Ret(a)
Definition: ftime.cpp:17
void hoc_startsw(void)
Definition: ftime.cpp:35
double nrn_time(void)
Definition: ftime.cpp:21
double nrn_timeus(void)
Definition: ftime.cpp:61
static time_t stop_time
Definition: ftime.cpp:13
static time_t start_time
Definition: ftime.cpp:12
void hoc_stopsw(void)
Definition: ftime.cpp:39
#define Printf
Definition: model.h:237