File: timing.cpp

package info (click to toggle)
faust 0.9.95~repack1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 164,732 kB
  • ctags: 18,777
  • sloc: cpp: 90,427; sh: 6,116; java: 4,501; objc: 4,428; ansic: 3,301; makefile: 1,298; ruby: 950; yacc: 511; xml: 398; lex: 218; python: 136
file content (60 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <cassert>
#ifndef WIN32
#include <sys/time.h>
#endif
#include "compatibility.hh"
#include "timing.hh"

using namespace std;

extern bool gTimingSwitch;

#if 1
double mysecond()
{
        struct timeval tp;
        struct timezone tzp;

        gettimeofday(&tp,&tzp);
        return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 );
}

int		lIndex=0;
double 	lStartTime[1024];
double 	lEndTime[1024];

static void tab (int n, ostream& fout)
{
        fout << '\n';
        while (n--)     fout << '\t'; 
}

void startTiming (const char* msg)
{
    if (gTimingSwitch) {
        assert(lIndex < 1023);
        tab(lIndex, cerr); cerr << "start " << msg << endl;
        lStartTime[lIndex++] = mysecond();
    }
}

void endTiming (const char* msg)
{
    if (gTimingSwitch) {
        assert(lIndex>0);
        lEndTime[--lIndex] = mysecond();
        tab(lIndex, cerr); cerr << "end " << msg << " (duration : " << lEndTime[lIndex] - lStartTime[lIndex] << ")" << endl;
    }
}

#else

void startTiming (const char* msg)
{}

void endTiming (const char* msg)
{}

#endif