Go to the documentation of this file.00001
00008
00009
00010
00011 #include <iostream>
00012 #include <sstream>
00013 #include <ecl/threads/priority.hpp>
00014 #include <ecl/time/stopwatch.hpp>
00015 #include <ecl/time/timestamp.hpp>
00016 #include <ecl/exceptions/standard_exception.hpp>
00017
00018
00019
00020
00021
00022 using std::string;
00023 using ecl::StopWatch;
00024 using ecl::TimeStamp;
00025 using ecl::ConfigurationError;
00026 using ecl::StandardException;
00027
00028
00029
00030
00031
00032 void f1() {
00033 int i = 0;
00034 if ( i == 1 ) {}
00035 }
00036
00037 void f2() throw(StandardException) {
00038 int i = 0;
00039 if ( i == 1 ) {}
00040 }
00041
00042 void f3() throw(StandardException) {
00043 int i = 0;
00044 if ( i == 1 ) {
00045 throw StandardException(LOC,ConfigurationError);
00046 }
00047 }
00048
00049 void f4() throw(StandardException) {
00050 int i = 0;
00051 if ( i == 1 ) {
00052 throw StandardException(LOC,ConfigurationError, "Standard exception with an extra string message.");
00053 }
00054 }
00055
00056 void f5() throw(StandardException) {
00057 throw StandardException(LOC,ConfigurationError);
00058 }
00059
00060 void f6() throw(StandardException) {
00061 throw StandardException(LOC,ConfigurationError, "Standard exception with an extra string message.");
00062 }
00063
00064 void g1() throw(StandardException) {
00065 double dude[5];
00066 for ( unsigned int j = 0; j < 5; ++j ) {
00067 dude[j] = 3.15*543/230.235;
00068 }
00069 }
00070
00071 void g2() throw(StandardException) {
00072 int i = 0;
00073 double dude[5];
00074 for ( unsigned int j = 0; j < 5; ++j ) {
00075 dude[j] = 3.15*543/230.235;
00076 }
00077 if ( i == 1 ) {
00078 throw StandardException(LOC,ConfigurationError, "Standard exception with an extra string message.");
00079 }
00080 }
00081
00082
00083
00084
00085
00086 int main()
00087 {
00088 try {
00089 ecl::set_priority(ecl::RealTimePriority4);
00090 } catch ( StandardException &e ) {
00091
00092 }
00093 StopWatch stopwatch;
00094 TimeStamp times[9];
00095
00096 stopwatch.restart();
00097 f1();
00098 times[0] = stopwatch.split();
00099 f2();
00100 times[1] = stopwatch.split();
00101 f3();
00102 times[2] = stopwatch.split();
00103 f4();
00104 times[3] = stopwatch.split();
00105 g1();
00106 times[4] = stopwatch.split();
00107 g2();
00108 times[5] = stopwatch.split();
00109 try {
00110 f2();
00111 } catch ( StandardException &e ) {
00112 }
00113 times[6] = stopwatch.split();
00114 try {
00115 f5();
00116 } catch ( StandardException &e ) {}
00117 times[7] = stopwatch.split();
00118 try {
00119 f6();
00120 } catch ( StandardException &e ) {}
00121 times[8] = stopwatch.split();
00122
00123
00124 stopwatch.restart();
00125 f1();
00126 times[0] = stopwatch.split();
00127 f2();
00128 times[1] = stopwatch.split();
00129 f3();
00130 times[2] = stopwatch.split();
00131 f4();
00132 times[3] = stopwatch.split();
00133 g1();
00134 times[4] = stopwatch.split();
00135 g2();
00136 times[5] = stopwatch.split();
00137
00138 try {
00139 f2();
00140 } catch ( StandardException &e ) {
00141 }
00142 times[6] = stopwatch.split();
00143 try {
00144 f5();
00145 } catch ( StandardException &e ) {}
00146 times[7] = stopwatch.split();
00147 try {
00148 f6();
00149 } catch ( StandardException &e ) {}
00150 times[8] = stopwatch.split();
00151
00152 std::cout << std::endl;
00153 std::cout << "***********************************************************" << std::endl;
00154 std::cout << " Performance comparison ecl exceptions" << std::endl;
00155 std::cout << "***********************************************************" << std::endl;
00156 std::cout << std::endl;
00157
00158 std::cout << "Simple Candidate Function " << " Time: " << times[0] << std::endl;
00159 std::cout << " Undeclared exception " << " Time: " << times[1] << std::endl;
00160 std::cout << " Unused exception " << " Time: " << times[2] << std::endl;
00161 std::cout << " Unused exception w/ string " << " Time: " << times[3] << std::endl;
00162 std::cout << std::endl;
00163 std::cout << "Complex Candidate Function " << " Time: " << times[4] << std::endl;
00164 std::cout << " Unused exception w/ string " << " Time: " << times[5] << std::endl;
00165 std::cout << std::endl;
00166 std::cout << "Try Catch Blocks " << std::endl;
00167 std::cout << " Uncaught exceptions " << " Time: " << times[6] << std::endl;
00168 std::cout << " Caught exception " << " Time: " << times[7] << std::endl;
00169 std::cout << " Caught exception w/string " << " Time: " << times[8] << std::endl;
00170
00171 std::cout << std::endl;
00172 std::cout << "***********************************************************" << std::endl;
00173 std::cout << " Conclusions" << std::endl;
00174 std::cout << "***********************************************************" << std::endl;
00175 std::cout << std::endl;
00176
00177 std::cout << "The following conclusions are after testing on a dual core." << std::endl;
00178 std::cout << std::endl;
00179 std::cout << " - In simple functions, unused ecl exceptions < 50ns." << std::endl;
00180 std::cout << " - String messages don't effect the cost of unused ecl exceptions." << std::endl;
00181 std::cout << " - Try-catch blocks have negligible cost." << std::endl;
00182 std::cout << " - String messages do impact caught messages ~1us." << std::endl;
00183 std::cout << std::endl;
00184 return 0;
00185 }
00186
00187