itom 1.4.0
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2013, Institut für Technische Optik (ITO), 00005 Universität Stuttgart, Germany 00006 00007 This file is part of itom. 00008 00009 itom is free software; you can redistribute it and/or modify it 00010 under the terms of the GNU Library General Public Licence as published by 00011 the Free Software Foundation; either version 2 of the Licence, or (at 00012 your option) any later version. 00013 00014 itom is distributed in the hope that it will be useful, but 00015 WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library 00017 General Public Licence for more details. 00018 00019 You should have received a copy of the GNU Library General Public License 00020 along with itom. If not, see <http://www.gnu.org/licenses/>. 00021 *********************************************************************** */ 00022 00023 #ifndef BENCHMARKS_H 00024 #define BENCHMARKS_H 00025 00026 #include <qmap.h> 00027 #include <qhash.h> 00028 00029 #include <qtextstream.h> 00030 #include <qfile.h> 00031 #include <qdatetime.h> 00032 #include <qdir.h> 00033 #include <qmutex.h> 00034 #include <qregexp.h> 00035 #include "opencv/cv.h" 00036 00037 void benchmarkTest1() 00038 { 00039 int64 start, ende; 00040 double freq = cv::getTickFrequency(); 00041 00042 //1 00043 int size = 1000000; 00044 int temp; 00045 00046 start = cv::getTickCount(); 00047 std::vector<int> a1; 00048 a1.resize(size); 00049 for(int i=0;i<size;i++) 00050 { 00051 a1[i]=2; 00052 temp=a1[i]; 00053 } 00054 a1.clear(); 00055 ende = cv::getTickCount(); 00056 qDebug() << "time: " << (ende-start)/freq; 00057 00058 start = cv::getTickCount(); 00059 int* a2 = new int[size]; 00060 for(int i=0;i<size;i++) 00061 { 00062 a2[i]=2; 00063 temp=a2[i]; 00064 } 00065 delete[] a2; 00066 ende = cv::getTickCount(); 00067 qDebug() << "time: " << (ende-start)/freq; 00068 } 00069 00070 void benchmarkTest2() 00071 { 00072 qDebug("benchmarkTest2"); 00073 int64 start, ende; 00074 double freq = cv::getTickFrequency(); 00075 00076 00077 //2 00078 int *test = (int*)(new cv::Mat()); 00079 int size = 1000000; 00080 cv::Mat* ptr = NULL; 00081 00082 start = cv::getTickCount(); 00083 for(int i=0;i<size;i++) 00084 { 00085 } 00086 ende = cv::getTickCount(); 00087 qDebug() << "time: " << (ende-start)/freq; 00088 00089 start = cv::getTickCount(); 00090 for(int i=0;i<size;i++) 00091 { 00092 ptr = (cv::Mat*)test; 00093 } 00094 ende = cv::getTickCount(); 00095 qDebug() << "time: " << (ende-start)/freq; 00096 00097 start = cv::getTickCount(); 00098 for(int i=0;i<size;i++) 00099 { 00100 ptr = reinterpret_cast<cv::Mat*>(test); 00101 } 00102 ende = cv::getTickCount(); 00103 qDebug() << "time: " << (ende-start)/freq; 00104 00105 00106 } 00107 00108 void benchmarkTest3() 00109 { 00110 ito::DataObject *do1 = NULL; //new ito::DataObject(10000,100,100,ito::tFloat32); 00111 ito::DataObject *do2 = NULL;//new ito::DataObject(*do1); 00112 00113 qDebug("benchmarkTest3"); 00114 int64 start, ende; 00115 double freq = cv::getTickFrequency(); 00116 00117 start = cv::getTickCount(); 00118 do1 = new ito::DataObject(10000,100,100,ito::tFloat32); 00119 ende = cv::getTickCount(); 00120 qDebug() << "time: " << (ende-start)/freq; 00121 00122 start = cv::getTickCount(); 00123 do2 = new ito::DataObject(*do1); 00124 ende = cv::getTickCount(); 00125 qDebug() << "time: " << (ende-start)/freq; 00126 00127 start = cv::getTickCount(); 00128 delete do2; 00129 ende = cv::getTickCount(); 00130 qDebug() << "time: " << (ende-start)/freq; 00131 00132 start = cv::getTickCount(); 00133 delete do1; 00134 ende = cv::getTickCount(); 00135 qDebug() << "time: " << (ende-start)/freq; 00136 00137 //int i=1; 00138 }; 00139 00140 void benchmarkTest4() 00141 { 00142 int64 start, ende; 00143 double freq = cv::getTickFrequency(); 00144 QString str1 = "guten tag kih ihiu oiuziuzt iztfzutfu iztuztriuz iuztiuztiuztzutut"; 00145 QString str2 = "guten tag kih ihiu oiuziuzt iztfzutfu iztuztriuz iuztiuztiuztzutut"; 00146 QByteArray ba1 = str1.toLatin1(); 00147 QByteArray ba2 = str2.toLatin1(); 00148 char *c1 = ba1.data(); 00149 char *c2 = ba2.data(); 00150 int num = 10000000; 00151 int c = -num; 00152 size_t size = sizeof(char) * std::min( strlen(c1),strlen(c2)); 00153 00154 qDebug() << "benchmarkTest4: " << num; 00155 c = 0; 00156 start = cv::getTickCount(); 00157 for(int i = 0; i< num;i++) 00158 { 00159 if(str1 == str2) {c++;}else{c--;} 00160 } 00161 ende = cv::getTickCount(); 00162 qDebug() << "time: " << (ende-start)/freq << " result: " << c; 00163 c = 0; 00164 start = cv::getTickCount(); 00165 for(int i = 0; i< num;i++) 00166 { 00167 if(ba1 == ba2) {c++;}else{c--;} 00168 } 00169 ende = cv::getTickCount(); 00170 qDebug() << "time: " << (ende-start)/freq << " result: " << c; 00171 c = 0; 00172 start = cv::getTickCount(); 00173 for(int i = 0; i< num;i++) 00174 { 00175 if(strcmp(c1,c2)) {c++;}else{c--;} 00176 } 00177 ende = cv::getTickCount(); 00178 qDebug() << "time: " << (ende-start)/freq << " result: " << c; 00179 c = 0; 00180 start = cv::getTickCount(); 00181 for(int i = 0; i< num;i++) 00182 { 00183 if(memcmp(c1,c2,size)) {c++;}else{c--;} 00184 } 00185 ende = cv::getTickCount(); 00186 qDebug() << "time: " << (ende-start)/freq << " result: " << c; 00187 00188 //int i=1; 00189 }; 00190 00191 void benchmarkTest5() 00192 { 00193 ito::DataObject *do1 = NULL; //new ito::DataObject(10000,100,100,ito::tFloat32); 00194 ito::DataObject *do2 = NULL;//new ito::DataObject(*do1); 00195 00196 qDebug("benchmarkTest5"); 00197 int64 start, ende; 00198 double freq = cv::getTickFrequency(); 00199 size_t j = 0; 00200 00201 start = cv::getTickCount(); 00202 for (size_t i = 0 ; i < 1000000; i++) 00203 { 00204 j += i; 00205 } 00206 ende = cv::getTickCount(); 00207 qDebug() << "time: " << (ende-start)/freq; 00208 00209 j = 0; 00210 start = cv::getTickCount(); 00211 for (size_t i = 0 ; i < 1000000; ++i) 00212 { 00213 j += i; 00214 } 00215 ende = cv::getTickCount(); 00216 qDebug() << "time: " << (ende-start)/freq; 00217 }; 00218 00219 typedef struct 00220 { 00221 union 00222 { 00223 union 00224 { 00225 struct 00226 { 00227 ito::uint8 b; 00228 ito::uint8 g; 00229 ito::uint8 r; 00230 ito::uint8 a; 00231 }; 00232 float rgb; 00233 }; 00234 ito::uint32 rgba; 00235 }; 00236 00237 } 00238 rgba32_; 00239 00240 void benchmarkTestColor() 00241 { 00242 int64 start, ende; 00243 double freq = cv::getTickFrequency(); 00244 size_t j = 0; 00245 00246 ito::rgba32 c1, c2; 00247 00248 start = cv::getTickCount(); 00249 for (size_t i = 0 ; i < 1000000; i++) 00250 { 00251 ito::rgba32 e1; 00252 } 00253 ende = cv::getTickCount(); 00254 qDebug() << "time: " << (ende-start)/freq; 00255 00256 start = cv::getTickCount(); 00257 for (size_t i = 0 ; i < 1000000; i++) 00258 { 00259 c1 = ito::rgba32(12,13,14,15); 00260 } 00261 ende = cv::getTickCount(); 00262 qDebug() << "time: " << (ende-start)/freq; 00263 00264 start = cv::getTickCount(); 00265 for (size_t i = 0 ; i < 1000000; i++) 00266 { 00267 c2 = c1; 00268 } 00269 ende = cv::getTickCount(); 00270 qDebug() << "time: " << (ende-start)/freq; 00271 00272 for (size_t i = 0 ; i < 1000000; i++) 00273 { 00274 unsigned int argb = c2.argb(); 00275 argb = argb+2; 00276 } 00277 ende = cv::getTickCount(); 00278 qDebug() << "time: " << (ende-start)/freq; 00279 00280 00281 00282 start = cv::getTickCount(); 00283 for (size_t i = 0 ; i < 1000000; i++) 00284 { 00285 rgba32_ e1; 00286 } 00287 ende = cv::getTickCount(); 00288 qDebug() << "time: " << (ende-start)/freq; 00289 00290 rgba32_ d1, d2; 00291 start = cv::getTickCount(); 00292 for (size_t i = 0 ; i < 1000000; i++) 00293 { 00294 d1.r = 13; 00295 d1.a = 12; 00296 d1.g = 14; 00297 d1.b = 15; 00298 } 00299 ende = cv::getTickCount(); 00300 qDebug() << "time: " << (ende-start)/freq; 00301 00302 start = cv::getTickCount(); 00303 00304 for (size_t i = 0 ; i < 1000000; i++) 00305 { 00306 d2 = d1; 00307 } 00308 ende = cv::getTickCount(); 00309 qDebug() << "time: " << (ende-start)/freq; 00310 00311 start = cv::getTickCount(); 00312 for (size_t i = 0 ; i < 1000000; i++) 00313 { 00314 unsigned int argb = d2.rgba; 00315 argb = argb+2; 00316 } 00317 ende = cv::getTickCount(); 00318 qDebug() << "time: " << (ende-start)/freq; 00319 00320 00321 qDebug() << "array construction"; 00322 start = cv::getTickCount(); 00323 ito::rgba32 h1[100000]; 00324 ende = cv::getTickCount(); 00325 qDebug() << "time: " << (ende-start)/freq; 00326 00327 start = cv::getTickCount(); 00328 rgba32_ h2[100000]; 00329 ende = cv::getTickCount(); 00330 qDebug() << "time: " << (ende-start)/freq; 00331 00332 start = cv::getTickCount(); 00333 ito::uint32 h3[100000]; 00334 ende = cv::getTickCount(); 00335 qDebug() << "time: " << (ende-start)/freq; 00336 } 00337 00338 00339 void startBenchmarks() 00340 { 00341 benchmarkTest1(); 00342 benchmarkTest2(); 00343 benchmarkTest3(); 00344 benchmarkTest4(); 00345 benchmarkTest5(); 00346 benchmarkTestColor(); 00347 } 00348 00349 #endif 00350 00351 00352 00353 00354 00355 00356 00357