da3d4e0e
dmayerich
Initial commit.
|
1
2
3
|
// add the following to a cpp file:
// PerformanceData PD;
|
bfe3f56b
dmayerich
Fixed Linux compa...
|
4
|
|
da3d4e0e
dmayerich
Initial commit.
|
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
|
#pragma once
#include <ostream>
using namespace std;
enum PerformanceDataType
{
PD_DISPLAY=0,
PD_SPS,
PD_UNUSED0,
//my stuff
SIMULATE_SPECTRUM,
SIMULATE_GPU,
KRAMERS_KRONIG,
//end my stuff
PERFORMANCE_DATA_TYPE_COUNT
};
static char PDTypeNames[][255] = {
"Display ",
"Simulation Total ",
" ----------------- ",
//my stuff
"Simulate Spectrum ",
" GPU Portion ",
"Kramers-Kronig ",
//end my stuff
};
|
bfe3f56b
dmayerich
Fixed Linux compa...
|
38
|
#ifdef WIN32
|
da3d4e0e
dmayerich
Initial commit.
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <stdio.h>
#include <windows.h>
#include <float.h>
#include <iostream>
#include <iomanip>
//-------------------------------------------------------------------------------
class PerformanceData
{
public:
PerformanceData() { ClearAll(); QueryPerformanceFrequency(&cps); }
~PerformanceData(){}
void ClearAll()
{
for ( int i=0; i<PERFORMANCE_DATA_TYPE_COUNT; i++ ) {
for ( int j=0; j<256; j++ ) times[i][j] = 0;
pos[i] = 0;
minTime[i] = 0xFFFFFFFF;
maxTime[i] = 0;
totalTime[i] = 0;
dataReady[i] = false;
}
}
|
bfe3f56b
dmayerich
Fixed Linux compa...
|
66
|
void StartTimer( int type ) { QueryPerformanceCounter( &startTime[type] );}
|
da3d4e0e
dmayerich
Initial commit.
|
67
68
69
|
void EndTimer( int type ) {
LARGE_INTEGER endTime;
QueryPerformanceCounter( &endTime );
|
52a5fe9d
dmayerich
Added double supp...
|
70
|
double t = (double)(endTime.QuadPart - startTime[type].QuadPart);
|
da3d4e0e
dmayerich
Initial commit.
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
//unsigned int t = GetTickCount() - startTime[type];
if ( t < minTime[type] ) minTime[type] = t;
if ( t > maxTime[type] ) maxTime[type] = t;
totalTime[type] -= times[type][ pos[type] ];
times[type][ pos[type] ] = t;
totalTime[type] += t;
pos[type]++;
if ( pos[type] == 0 ) dataReady[type] = true;
}
void PrintResult( ostream &os,int i=PERFORMANCE_DATA_TYPE_COUNT)
{
os.setf(ios::fixed);
if ((i<PERFORMANCE_DATA_TYPE_COUNT)&&(i>=0)){
double a = GetAvrgTime(i);
if ( a )
os<< PDTypeNames[i]<<" : avrg="<<setw(8)<<setprecision(3)<<a<<"\tmin="<<setw(8)<<setprecision(3)<< GetMinTime(i) <<"\tmax="<<setw(8)<<setprecision(3)<< GetMaxTime(i) <<endl ;
else
os<< PDTypeNames[i]<<" : avrg= -----\tmin= -----\tmax= -----"<<endl;
}
}
void PrintResults( ostream &os)
{
for ( int i=0; i<PERFORMANCE_DATA_TYPE_COUNT; i++ )
PrintResult(os,i);
}
double GetLastTime( int type ) { return times[type][pos[type]]; }
double GetAvrgTime( int type ) { double a = 1000.0 * totalTime[type] / (float)cps.QuadPart / ( (dataReady[type]) ? 256.0 : (double)pos[type] ); return (_finite(a))? a:0; }
double GetMinTime( int type ) { return 1000.0 * minTime[type] / (float)cps.LowPart; }
double GetMaxTime( int type ) { return 1000.0 * maxTime[type] / (float)cps.LowPart; }
private:
double times[PERFORMANCE_DATA_TYPE_COUNT][256];
unsigned char pos[PERFORMANCE_DATA_TYPE_COUNT];
LARGE_INTEGER startTime[PERFORMANCE_DATA_TYPE_COUNT];
double minTime[ PERFORMANCE_DATA_TYPE_COUNT ];
double maxTime[ PERFORMANCE_DATA_TYPE_COUNT ];
double totalTime[ PERFORMANCE_DATA_TYPE_COUNT ];
bool dataReady[ PERFORMANCE_DATA_TYPE_COUNT ];
LARGE_INTEGER cps;
};
//-------------------------------------------------------------------------------
|
bfe3f56b
dmayerich
Fixed Linux compa...
|
116
|
#else
|
da3d4e0e
dmayerich
Initial commit.
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
class PerformanceData{
public:
PerformanceData() {;};
~PerformanceData(){;};
void ClearAll(){;};
void StartTimer( int type ) {;};
void EndTimer( int type ) {;};
void PrintResults( ostream &os){;};
void PrintResult( ostream &os, int i=PERFORMANCE_DATA_TYPE_COUNT){;};
double GetLastTime( int type ) { return 0.0; };
double GetAvrgTime( int type ) { return 0.0; };
double GetMinTime( int type ) { return 0.0; };
double GetMaxTime( int type ) { return 0.0; };
};
#endif
//-------------------------------------------------------------------------------
|
bfe3f56b
dmayerich
Fixed Linux compa...
|
135
|
|
da3d4e0e
dmayerich
Initial commit.
|
136
137
138
|
extern PerformanceData PD;
//-------------------------------------------------------------------------------
|