FAUST compiler  0.9.9.6b8
timing.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <cassert>
3 #ifndef WIN32
4 #include <sys/time.h>
5 #endif
6 #include "compatibility.hh"
7 #include "timing.hh"
8 
9 using namespace std;
10 
11 extern bool gTimingSwitch;
12 
13 #if 1
14 double mysecond()
15 {
16  struct timeval tp;
17  struct timezone tzp;
18  int i;
19 
20  i = gettimeofday(&tp,&tzp);
21  return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 );
22 }
23 
24 int lIndex=0;
25 double lStartTime[1024];
26 double lEndTime[1024];
27 
28 static void tab (int n, ostream& fout)
29 {
30  fout << '\n';
31  while (n--) fout << '\t';
32 }
33 
34 void startTiming (const char* msg)
35 {
36  if (gTimingSwitch) {
37  assert(lIndex < 1023);
38  tab(lIndex, cerr); cerr << "start " << msg << endl;
39  lStartTime[lIndex++] = mysecond();
40  }
41 }
42 
43 void endTiming (const char* msg)
44 {
45  if (gTimingSwitch) {
46  assert(lIndex>0);
47  lEndTime[--lIndex] = mysecond();
48  tab(lIndex, cerr); cerr << "end " << msg << " (duration : " << lEndTime[lIndex] - lStartTime[lIndex] << ")" << endl;
49  }
50 }
51 
52 #else
53 
54 void startTiming (const char* msg)
55 {}
56 
57 void endTiming (const char* msg)
58 {}
59 
60 #endif
61 
void endTiming(const char *msg)
Definition: timing.cpp:43
static void tab(int n, ostream &fout)
Definition: timing.cpp:28
void startTiming(const char *msg)
Definition: timing.cpp:34
double lEndTime[1024]
Definition: timing.cpp:26
double lStartTime[1024]
Definition: timing.cpp:25
bool gTimingSwitch
Definition: main.cpp:115
double mysecond()
Definition: timing.cpp:14
int lIndex
Definition: timing.cpp:24