forked from Ramblurr/scriptbots
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPerfTimer.cpp
63 lines (52 loc) · 1.55 KB
/
PerfTimer.cpp
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
61
62
63
#include "PerfTimer.h"
#include <iostream>
#include <stdio.h>
#include <omp.h>
#include <time.h>
#include "settings.h" // so we can access NUM_THREADS
using namespace std;
PerfTimer::PerfTimer()
{
totalTimes = map<string, double>();
intermediateTimes = map<string, double>();
}
void PerfTimer::start(string key)
{
//time(&(intermediateTimes[key]));
intermediateTimes[key] = getSimpleTime();
//intermediateTimes[key] = time();
}
void PerfTimer::end(string key)
{
// time_t endTime;
//double endTime = getSimpleTime();
//time(&endTime);
//totalTimes[key] += (endTime - intermediateTimes[key]);
//totalTimes[key] += difftime(endTime, intermediateTimes[key]);
totalTimes[key] += (getSimpleTime() - intermediateTimes[key]);
}
void PerfTimer::printTimes(){
map<string, double>::iterator it;
cout << endl;
cout << "-------------------------------------------------------------------------------" << endl;
cout << "Timing metrics: " << endl;
double total_time = totalTimes["total"];
for(it=totalTimes.begin(); it != totalTimes.end(); it++)
{
//printf("%s : %.2lf\n", it->first.c_str(), it->second);
printf("%6.2f%% : %s\n", it->second/total_time*100, it->first.c_str());
//cout << " " << it->first << ": " << it->second << endl;
}
cout << endl << "Copy to Spreadsheet:" << endl;
for(it=totalTimes.begin(); it != totalTimes.end(); it++)
{
printf("%.2lf\t", it->second);
}
printf("%d", NUM_THREADS);
}
double PerfTimer::getSimpleTime(){
struct timeval t;
struct timezone tzp;
gettimeofday(&t, &tzp);
return t.tv_sec + t.tv_usec*1e-6;
}