itom  3.0.0
benchmarks.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef BENCHMARKS_H
24 #define BENCHMARKS_H
25 
26 #include <qmap.h>
27 #include <qhash.h>
28 
29 #include <qtextstream.h>
30 #include <qfile.h>
31 #include <qdatetime.h>
32 #include <qdir.h>
33 #include <qmutex.h>
34 #include <qregexp.h>
35 #include "opencv/cv.h"
36 
37 void benchmarkTest1()
38 {
39  int64 start, ende;
40  double freq = cv::getTickFrequency();
41 
42  //1
43  int size = 1000000;
44  int temp;
45 
46  start = cv::getTickCount();
47  std::vector<int> a1;
48  a1.resize(size);
49  for(int i=0;i<size;i++)
50  {
51  a1[i]=2;
52  temp=a1[i];
53  }
54  a1.clear();
55  ende = cv::getTickCount();
56  qDebug() << "time: " << (ende-start)/freq;
57 
58  start = cv::getTickCount();
59  int* a2 = new int[size];
60  for(int i=0;i<size;i++)
61  {
62  a2[i]=2;
63  temp=a2[i];
64  }
65  delete[] a2;
66  ende = cv::getTickCount();
67  qDebug() << "time: " << (ende-start)/freq;
68 }
69 
70 void benchmarkTest2()
71 {
72  qDebug("benchmarkTest2");
73  int64 start, ende;
74  double freq = cv::getTickFrequency();
75 
76 
77  //2
78  int *test = (int*)(new cv::Mat());
79  int size = 1000000;
80  cv::Mat* ptr = NULL;
81 
82  start = cv::getTickCount();
83  for(int i=0;i<size;i++)
84  {
85  }
86  ende = cv::getTickCount();
87  qDebug() << "time: " << (ende-start)/freq;
88 
89  start = cv::getTickCount();
90  for(int i=0;i<size;i++)
91  {
92  ptr = (cv::Mat*)test;
93  }
94  ende = cv::getTickCount();
95  qDebug() << "time: " << (ende-start)/freq;
96 
97  start = cv::getTickCount();
98  for(int i=0;i<size;i++)
99  {
100  ptr = reinterpret_cast<cv::Mat*>(test);
101  }
102  ende = cv::getTickCount();
103  qDebug() << "time: " << (ende-start)/freq;
104 
105 
106 }
107 
108 void benchmarkTest3()
109 {
110  ito::DataObject *do1 = NULL; //new ito::DataObject(10000,100,100,ito::tFloat32);
111  ito::DataObject *do2 = NULL;//new ito::DataObject(*do1);
112 
113  qDebug("benchmarkTest3");
114  int64 start, ende;
115  double freq = cv::getTickFrequency();
116 
117  start = cv::getTickCount();
118  do1 = new ito::DataObject(10000,100,100,ito::tFloat32);
119  ende = cv::getTickCount();
120  qDebug() << "time: " << (ende-start)/freq;
121 
122  start = cv::getTickCount();
123  do2 = new ito::DataObject(*do1);
124  ende = cv::getTickCount();
125  qDebug() << "time: " << (ende-start)/freq;
126 
127  start = cv::getTickCount();
128  delete do2;
129  ende = cv::getTickCount();
130  qDebug() << "time: " << (ende-start)/freq;
131 
132  start = cv::getTickCount();
133  delete do1;
134  ende = cv::getTickCount();
135  qDebug() << "time: " << (ende-start)/freq;
136 
137  //int i=1;
138 };
139 
140 void benchmarkTest4()
141 {
142  int64 start, ende;
143  double freq = cv::getTickFrequency();
144  QString str1 = "guten tag kih ihiu oiuziuzt iztfzutfu iztuztriuz iuztiuztiuztzutut";
145  QString str2 = "guten tag kih ihiu oiuziuzt iztfzutfu iztuztriuz iuztiuztiuztzutut";
146  QByteArray ba1 = str1.toLatin1();
147  QByteArray ba2 = str2.toLatin1();
148  char *c1 = ba1.data();
149  char *c2 = ba2.data();
150  int num = 10000000;
151  int c = -num;
152  size_t size = sizeof(char) * std::min( strlen(c1),strlen(c2));
153 
154  qDebug() << "benchmarkTest4: " << num;
155  c = 0;
156  start = cv::getTickCount();
157  for(int i = 0; i< num;i++)
158  {
159  if(str1 == str2) {c++;}else{c--;}
160  }
161  ende = cv::getTickCount();
162  qDebug() << "time: " << (ende-start)/freq << " result: " << c;
163  c = 0;
164  start = cv::getTickCount();
165  for(int i = 0; i< num;i++)
166  {
167  if(ba1 == ba2) {c++;}else{c--;}
168  }
169  ende = cv::getTickCount();
170  qDebug() << "time: " << (ende-start)/freq << " result: " << c;
171  c = 0;
172  start = cv::getTickCount();
173  for(int i = 0; i< num;i++)
174  {
175  if(strcmp(c1,c2)) {c++;}else{c--;}
176  }
177  ende = cv::getTickCount();
178  qDebug() << "time: " << (ende-start)/freq << " result: " << c;
179  c = 0;
180  start = cv::getTickCount();
181  for(int i = 0; i< num;i++)
182  {
183  if(memcmp(c1,c2,size)) {c++;}else{c--;}
184  }
185  ende = cv::getTickCount();
186  qDebug() << "time: " << (ende-start)/freq << " result: " << c;
187 
188  //int i=1;
189 };
190 
191 void benchmarkTest5()
192 {
193  ito::DataObject *do1 = NULL; //new ito::DataObject(10000,100,100,ito::tFloat32);
194  ito::DataObject *do2 = NULL;//new ito::DataObject(*do1);
195 
196  qDebug("benchmarkTest5");
197  int64 start, ende;
198  double freq = cv::getTickFrequency();
199  size_t j = 0;
200 
201  start = cv::getTickCount();
202  for (size_t i = 0 ; i < 1000000; i++)
203  {
204  j += i;
205  }
206  ende = cv::getTickCount();
207  qDebug() << "time: " << (ende-start)/freq;
208 
209  j = 0;
210  start = cv::getTickCount();
211  for (size_t i = 0 ; i < 1000000; ++i)
212  {
213  j += i;
214  }
215  ende = cv::getTickCount();
216  qDebug() << "time: " << (ende-start)/freq;
217 };
218 
219 typedef struct
220 {
221  union
222  {
223  union
224  {
225  struct
226  {
227  ito::uint8 b;
228  ito::uint8 g;
229  ito::uint8 r;
230  ito::uint8 a;
231  };
232  float rgb;
233  };
234  ito::uint32 rgba;
235  };
236 
237 }
238 rgba32_;
239 
240 void benchmarkTestColor()
241 {
242  int64 start, ende;
243  double freq = cv::getTickFrequency();
244  size_t j = 0;
245 
246  ito::rgba32 c1, c2;
247 
248  start = cv::getTickCount();
249  for (size_t i = 0 ; i < 1000000; i++)
250  {
251  ito::rgba32 e1;
252  }
253  ende = cv::getTickCount();
254  qDebug() << "time: " << (ende-start)/freq;
255 
256  start = cv::getTickCount();
257  for (size_t i = 0 ; i < 1000000; i++)
258  {
259  c1 = ito::rgba32(12,13,14,15);
260  }
261  ende = cv::getTickCount();
262  qDebug() << "time: " << (ende-start)/freq;
263 
264  start = cv::getTickCount();
265  for (size_t i = 0 ; i < 1000000; i++)
266  {
267  c2 = c1;
268  }
269  ende = cv::getTickCount();
270  qDebug() << "time: " << (ende-start)/freq;
271 
272  for (size_t i = 0 ; i < 1000000; i++)
273  {
274  unsigned int argb = c2.argb();
275  argb = argb+2;
276  }
277  ende = cv::getTickCount();
278  qDebug() << "time: " << (ende-start)/freq;
279 
280 
281 
282  start = cv::getTickCount();
283  for (size_t i = 0 ; i < 1000000; i++)
284  {
285  rgba32_ e1;
286  }
287  ende = cv::getTickCount();
288  qDebug() << "time: " << (ende-start)/freq;
289 
290  rgba32_ d1, d2;
291  start = cv::getTickCount();
292  for (size_t i = 0 ; i < 1000000; i++)
293  {
294  d1.r = 13;
295  d1.a = 12;
296  d1.g = 14;
297  d1.b = 15;
298  }
299  ende = cv::getTickCount();
300  qDebug() << "time: " << (ende-start)/freq;
301 
302  start = cv::getTickCount();
303 
304  for (size_t i = 0 ; i < 1000000; i++)
305  {
306  d2 = d1;
307  }
308  ende = cv::getTickCount();
309  qDebug() << "time: " << (ende-start)/freq;
310 
311  start = cv::getTickCount();
312  for (size_t i = 0 ; i < 1000000; i++)
313  {
314  unsigned int argb = d2.rgba;
315  argb = argb+2;
316  }
317  ende = cv::getTickCount();
318  qDebug() << "time: " << (ende-start)/freq;
319 
320 
321  qDebug() << "array construction";
322  start = cv::getTickCount();
323  ito::rgba32 h1[100000];
324  ende = cv::getTickCount();
325  qDebug() << "time: " << (ende-start)/freq;
326 
327  start = cv::getTickCount();
328  rgba32_ h2[100000];
329  ende = cv::getTickCount();
330  qDebug() << "time: " << (ende-start)/freq;
331 
332  start = cv::getTickCount();
333  ito::uint32 h3[100000];
334  ende = cv::getTickCount();
335  qDebug() << "time: " << (ende-start)/freq;
336 }
337 
338 
339 void startBenchmarks()
340 {
341  benchmarkTest1();
342  benchmarkTest2();
343  benchmarkTest3();
344  benchmarkTest4();
345  benchmarkTest5();
346  benchmarkTestColor();
347 }
348 
349 #endif
350 
351 
352 
353 
354 
355 
356 
357 
dataObject contains a n-dimensional matrix
Definition: dataobj.h:496
Definition: typeDefs.h:85
Definition: benchmarks.h:219