FAUST compiler  0.9.9.6b8
timing.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <cassert>
00003 #ifndef WIN32
00004 #include <sys/time.h>
00005 #endif
00006 #include "timing.hh"
00007 
00008 using namespace std;
00009 
00010 
00011 #if 0
00012 double mysecond()
00013 {
00014         struct timeval tp;
00015         struct timezone tzp;
00016         int i;
00017 
00018         i = gettimeofday(&tp,&tzp);
00019         return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 );
00020 }
00021 
00022 int     lIndex=0;
00023 double  lStartTime[1024];
00024 double  lEndTime[1024];
00025 
00026 static void tab (int n, ostream& fout)
00027 {
00028         fout << '\n';
00029         while (n--)     fout << '\t'; 
00030 }
00031 
00032 void startTiming (const char* msg)
00033 {
00034     assert(lIndex < 1023);
00035     tab(lIndex, cerr); cerr << "start " << msg << endl;
00036     lStartTime[lIndex++] = mysecond();
00037 }
00038 
00039 void endTiming (const char* msg)
00040 {
00041     assert(lIndex>0);
00042     lEndTime[--lIndex] = mysecond();
00043     tab(lIndex, cerr); cerr << "end " << msg << " (duration : " << lEndTime[lIndex] - lStartTime[lIndex] << ")" << endl;
00044 }
00045 
00046 #else
00047 
00048 void startTiming (const char* msg)
00049 {}
00050 
00051 void endTiming (const char* msg)
00052 {}
00053 
00054 #endif
00055