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) hoc_ret(); hoc_pushx(a);
18 
19 double nrn_time(void)
20 {
21 #if defined(HAVE_GETTIMEOFDAY)
22  int ms10;
23  struct timeval x;
24  gettimeofday(&x, (struct timezone*)0);
25  ms10 = x.tv_usec/10000;
26  start_time = (100.*(double)(x.tv_sec) + (double)ms10)/100.;
27  return (start_time);
28 #else
29  return ((double)time(&start_time));
30 #endif
31 }
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 {
63 #if defined(HAVE_GETTIMEOFDAY)
64  struct timeval x;
65  gettimeofday(&x, (struct timezone*)0);
66  return ((double)x.tv_sec + .000001*((double)x.tv_usec));
67 #else
68  return 0.;
69 #endif
70 }
71 
#define Printf
Definition: model.h:252
void hoc_startsw(void)
Definition: ftime.cpp:35
double nrn_timeus(void)
Definition: ftime.cpp:61
#define Ret(a)
Definition: ftime.cpp:17
static time_t stop_time
Definition: ftime.cpp:13
static time_t start_time
Definition: ftime.cpp:12
double nrn_time(void)
Definition: ftime.cpp:19
void hoc_stopsw(void)
Definition: ftime.cpp:39