ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
timer.h
Go to the documentation of this file.
1 
19 #ifndef __TIMER_H__
20 #define __TIMER_H__
21 
22 #include <sys/time.h>
23 #include <string>
24 #include <iostream>
25 #include <stdlib.h>
26 #include "typedefs.h"
27 
28 //Note do not change P_FIRST and P_LAST and keep them pointing to the first and last element in the enum
29 enum ABYPHASE {
30  P_TOTAL, P_INIT, P_CIRCUIT, P_NETWORK, P_BASE_OT, P_SETUP, P_OT_EXT, P_GARBLE, P_ONLINE, P_FIRST = P_TOTAL, P_LAST = P_ONLINE
31 };
32 struct aby_timings {
33  double timing;
34  timeval tbegin;
35  timeval tend;
36 };
37 
38 static int m_nTimings = P_LAST - P_FIRST + 1;
39 static aby_timings m_tTimes[P_LAST - P_FIRST + 1];
40 using namespace std;
41 
42 // Timing routines
43 static double getMillies(timeval timestart, timeval timeend) {
44  long time1 = (timestart.tv_sec * 1000000) + (timestart.tv_usec);
45  long time2 = (timeend.tv_sec * 1000000) + (timeend.tv_usec);
46 
47  return (double) (time2 - time1) / 1000;
48 }
49 
50 // Timing routines
51 static double getMillies(timespec timestart, timespec timeend) {
52  long time1 = (timestart.tv_sec * 1000000) + (timestart.tv_nsec / 1000);
53  long time2 = (timeend.tv_sec * 1000000) + (timeend.tv_nsec / 1000);
54 
55  return (double) (time2 - time1) / 1000;
56 }
57 
58 static void StartWatch(const string& msg, ABYPHASE phase) {
59  if (phase < P_FIRST && phase > P_LAST) {
60  cerr << "Phase not recognized: " << phase << endl;
61  return;
62  }
63  gettimeofday(&(m_tTimes[phase].tbegin), NULL);
64 #ifndef BATCH
65  cout << msg << endl;
66 #endif
67 }
68 
69 static void StopWatch(const string& msg, ABYPHASE phase) {
70  if (phase < P_FIRST && phase > P_LAST) {
71  cerr << "Phase not recognized: " << phase << endl;
72  return;
73  }
74 
75  gettimeofday(&(m_tTimes[phase].tend), NULL);
76  m_tTimes[phase].timing = getMillies(m_tTimes[phase].tbegin, m_tTimes[phase].tend);
77 
78 #ifndef BATCH
79  cout << msg << m_tTimes[phase].timing << " ms " << endl;
80 #endif
81 
82 }
83 
84 static void PrintTimings() {
85  string unit = " ms";
86  cout << "Timings: " << endl;
87  cout << "Total =\t\t" << m_tTimes[0].timing << unit << endl;
88  cout << "Init =\t\t" << m_tTimes[1].timing << unit << endl;
89  cout << "CircuitGen =\t" << m_tTimes[2].timing << unit << endl;
90  cout << "Network =\t" << m_tTimes[3].timing << unit << endl;
91  cout << "BaseOTs =\t" << m_tTimes[4].timing << unit << endl;
92  cout << "Setup =\t\t" << m_tTimes[5].timing << unit << endl;
93  cout << "OTExtension =\t" << m_tTimes[6].timing << unit << endl;
94  cout << "Garbling =\t" << m_tTimes[7].timing << unit << endl;
95  cout << "Online =\t" << m_tTimes[8].timing << unit << endl;
96 }
97 
98 static double GetTimeForPhase(ABYPHASE phase) {
99  return m_tTimes[phase].timing;
100 }
101 
102 #endif /* TIMER_H_ */
Definition: timer.h:32
Typedefs Implementation.