exceptions.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 #include <iostream>
12 #include <sstream>
13 #include <ecl/threads/priority.hpp>
14 #include <ecl/time/stopwatch.hpp>
15 #include <ecl/time/timestamp.hpp>
17 
18 /*****************************************************************************
19 ** Using
20 *****************************************************************************/
21 
22 using std::string;
23 using ecl::StopWatch;
24 using ecl::TimeStamp;
27 
28 /*****************************************************************************
29 ** Globals
30 *****************************************************************************/
31 
32 void f1() {
33  int i = 0;
34  if ( i == 1 ) {}
35 }
36 
37 void f2() throw(StandardException) {
38  int i = 0;
39  if ( i == 1 ) {}
40 }
41 
42 void f3() throw(StandardException) {
43  int i = 0;
44  if ( i == 1 ) {
45  throw StandardException(LOC,ConfigurationError);
46  }
47 }
48 
49 void f4() throw(StandardException) {
50  int i = 0;
51  if ( i == 1 ) {
52  throw StandardException(LOC,ConfigurationError, "Standard exception with an extra string message.");
53  }
54 }
55 
56 void f5() throw(StandardException) {
57  throw StandardException(LOC,ConfigurationError);
58 }
59 
60 void f6() throw(StandardException) {
61  throw StandardException(LOC,ConfigurationError, "Standard exception with an extra string message.");
62 }
63 
64 void g1() throw(StandardException) {
65  double dude[5];
66  for ( unsigned int j = 0; j < 5; ++j ) {
67  dude[j] = 3.15*543/230.235;
68  }
69 }
70 
71 void g2() throw(StandardException) {
72  int i = 0;
73  double dude[5];
74  for ( unsigned int j = 0; j < 5; ++j ) {
75  dude[j] = 3.15*543/230.235;
76  }
77  if ( i == 1 ) {
78  throw StandardException(LOC,ConfigurationError, "Standard exception with an extra string message.");
79  }
80 }
81 
82 /*****************************************************************************
83 ** Main
84 *****************************************************************************/
85 
86 int main()
87 {
88  try {
89  ecl::set_priority(ecl::RealTimePriority4);
90  } catch ( StandardException &e ) {
91  // dont worry about it.
92  }
93  StopWatch stopwatch;
94  TimeStamp times[9];
95 
96  stopwatch.restart();
97  f1();
98  times[0] = stopwatch.split();
99  f2();
100  times[1] = stopwatch.split();
101  f3();
102  times[2] = stopwatch.split();
103  f4();
104  times[3] = stopwatch.split();
105  g1();
106  times[4] = stopwatch.split();
107  g2();
108  times[5] = stopwatch.split();
109  try {
110  f2();
111  } catch ( StandardException &e ) {
112  }
113  times[6] = stopwatch.split();
114  try {
115  f5();
116  } catch ( StandardException &e ) {}
117  times[7] = stopwatch.split();
118  try {
119  f6();
120  } catch ( StandardException &e ) {}
121  times[8] = stopwatch.split();
122 
123  // Try and negate the effects of caching on early instructions (i.e. get right into cache).
124  stopwatch.restart();
125  f1();
126  times[0] = stopwatch.split();
127  f2();
128  times[1] = stopwatch.split();
129  f3();
130  times[2] = stopwatch.split();
131  f4();
132  times[3] = stopwatch.split();
133  g1();
134  times[4] = stopwatch.split();
135  g2();
136  times[5] = stopwatch.split();
137 
138  try {
139  f2();
140  } catch ( StandardException &e ) {
141  }
142  times[6] = stopwatch.split();
143  try {
144  f5();
145  } catch ( StandardException &e ) {}
146  times[7] = stopwatch.split();
147  try {
148  f6();
149  } catch ( StandardException &e ) {}
150  times[8] = stopwatch.split();
151 
152  std::cout << std::endl;
153  std::cout << "***********************************************************" << std::endl;
154  std::cout << " Performance comparison ecl exceptions" << std::endl;
155  std::cout << "***********************************************************" << std::endl;
156  std::cout << std::endl;
157 
158  std::cout << "Simple Candidate Function " << " Time: " << times[0] << std::endl;
159  std::cout << " Undeclared exception " << " Time: " << times[1] << std::endl;
160  std::cout << " Unused exception " << " Time: " << times[2] << std::endl;
161  std::cout << " Unused exception w/ string " << " Time: " << times[3] << std::endl;
162  std::cout << std::endl;
163  std::cout << "Complex Candidate Function " << " Time: " << times[4] << std::endl;
164  std::cout << " Unused exception w/ string " << " Time: " << times[5] << std::endl;
165  std::cout << std::endl;
166  std::cout << "Try Catch Blocks " << std::endl;
167  std::cout << " Uncaught exceptions " << " Time: " << times[6] << std::endl;
168  std::cout << " Caught exception " << " Time: " << times[7] << std::endl;
169  std::cout << " Caught exception w/string " << " Time: " << times[8] << std::endl;
170 
171  std::cout << std::endl;
172  std::cout << "***********************************************************" << std::endl;
173  std::cout << " Conclusions" << std::endl;
174  std::cout << "***********************************************************" << std::endl;
175  std::cout << std::endl;
176 
177  std::cout << "The following conclusions are after testing on a dual core." << std::endl;
178  std::cout << std::endl;
179  std::cout << " - In simple functions, unused ecl exceptions < 50ns." << std::endl;
180  std::cout << " - String messages don't effect the cost of unused ecl exceptions." << std::endl;
181  std::cout << " - Try-catch blocks have negligible cost." << std::endl;
182  std::cout << " - String messages do impact caught messages ~1us." << std::endl;
183  std::cout << std::endl;
184  return 0;
185 }
186 
187 
int main()
Definition: exceptions.cpp:86
void f3()
Definition: exceptions.cpp:42
#define LOC
void f2()
Definition: exceptions.cpp:37
RealTimePriority4
ConfigurationError
void g1()
Definition: exceptions.cpp:64
void f4()
Definition: exceptions.cpp:49
void f6()
Definition: exceptions.cpp:60
void g2()
Definition: exceptions.cpp:71
void f1()
Definition: exceptions.cpp:32
void f5()
Definition: exceptions.cpp:56


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:55