itom  4.1.0
benchmarks.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2018, 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 "opencv2/opencv.hpp"
36 #include <iostream>
37 #include "DataObject\dataobj.h"
38 #include "common/typeDefs.h"
39 #include "common/color.h"
40 
41 void benchmarkTest1()
42 {
43  int64 start, ende;
44  double freq = cv::getTickFrequency();
45 
46  //1
47  int size = 1000000;
48  int temp;
49 
50  start = cv::getTickCount();
51  std::vector<int> a1;
52  a1.resize(size);
53  for(int i=0;i<size;i++)
54  {
55  a1[i]=2;
56  temp=a1[i];
57  }
58  a1.clear();
59  ende = cv::getTickCount();
60  qDebug() << "time: " << (ende-start)/freq;
61 
62  start = cv::getTickCount();
63  int* a2 = new int[size];
64  for(int i=0;i<size;i++)
65  {
66  a2[i]=2;
67  temp=a2[i];
68  }
69  delete[] a2;
70  ende = cv::getTickCount();
71  qDebug() << "time: " << (ende-start)/freq;
72 }
73 
74 void benchmarkTest2()
75 {
76  qDebug("benchmarkTest2");
77  int64 start, ende;
78  double freq = cv::getTickFrequency();
79 
80 
81  //2
82  int *test = (int*)(new cv::Mat());
83  int size = 1000000;
84  cv::Mat* ptr = NULL;
85 
86  start = cv::getTickCount();
87  for(int i=0;i<size;i++)
88  {
89  }
90  ende = cv::getTickCount();
91  qDebug() << "time: " << (ende-start)/freq;
92 
93  start = cv::getTickCount();
94  for(int i=0;i<size;i++)
95  {
96  ptr = (cv::Mat*)test;
97  }
98  ende = cv::getTickCount();
99  qDebug() << "time: " << (ende-start)/freq;
100 
101  start = cv::getTickCount();
102  for(int i=0;i<size;i++)
103  {
104  ptr = reinterpret_cast<cv::Mat*>(test);
105  }
106  ende = cv::getTickCount();
107  qDebug() << "time: " << (ende-start)/freq;
108 
109 
110 }
111 
112 void benchmarkTest3()
113 {
114  ito::DataObject *do1 = NULL; //new ito::DataObject(10000,100,100,ito::tFloat32);
115  ito::DataObject *do2 = NULL;//new ito::DataObject(*do1);
116 
117  qDebug("benchmarkTest3");
118  int64 start, ende;
119  double freq = cv::getTickFrequency();
120 
121  start = cv::getTickCount();
122  do1 = new ito::DataObject(10000,100,100,ito::tFloat32);
123  ende = cv::getTickCount();
124  qDebug() << "time: " << (ende-start)/freq;
125 
126  start = cv::getTickCount();
127  do2 = new ito::DataObject(*do1);
128  ende = cv::getTickCount();
129  qDebug() << "time: " << (ende-start)/freq;
130 
131  start = cv::getTickCount();
132  delete do2;
133  ende = cv::getTickCount();
134  qDebug() << "time: " << (ende-start)/freq;
135 
136  start = cv::getTickCount();
137  delete do1;
138  ende = cv::getTickCount();
139  qDebug() << "time: " << (ende-start)/freq;
140 
141  //int i=1;
142 };
143 
144 void benchmarkTest4()
145 {
146  int64 start, ende;
147  double freq = cv::getTickFrequency();
148  QString str1 = "guten tag kih ihiu oiuziuzt iztfzutfu iztuztriuz iuztiuztiuztzutut";
149  QString str2 = "guten tag kih ihiu oiuziuzt iztfzutfu iztuztriuz iuztiuztiuztzutut";
150  QByteArray ba1 = str1.toLatin1();
151  QByteArray ba2 = str2.toLatin1();
152  char *c1 = ba1.data();
153  char *c2 = ba2.data();
154  int num = 10000000;
155  int c = -num;
156  size_t size = sizeof(char) * std::min( strlen(c1),strlen(c2));
157 
158  qDebug() << "benchmarkTest4: " << num;
159  c = 0;
160  start = cv::getTickCount();
161  for(int i = 0; i< num;i++)
162  {
163  if(str1 == str2) {c++;}else{c--;}
164  }
165  ende = cv::getTickCount();
166  qDebug() << "time: " << (ende-start)/freq << " result: " << c;
167  c = 0;
168  start = cv::getTickCount();
169  for(int i = 0; i< num;i++)
170  {
171  if(ba1 == ba2) {c++;}else{c--;}
172  }
173  ende = cv::getTickCount();
174  qDebug() << "time: " << (ende-start)/freq << " result: " << c;
175  c = 0;
176  start = cv::getTickCount();
177  for(int i = 0; i< num;i++)
178  {
179  if(strcmp(c1,c2)) {c++;}else{c--;}
180  }
181  ende = cv::getTickCount();
182  qDebug() << "time: " << (ende-start)/freq << " result: " << c;
183  c = 0;
184  start = cv::getTickCount();
185  for(int i = 0; i< num;i++)
186  {
187  if(memcmp(c1,c2,size)) {c++;}else{c--;}
188  }
189  ende = cv::getTickCount();
190  qDebug() << "time: " << (ende-start)/freq << " result: " << c;
191 
192  //int i=1;
193 };
194 
195 void benchmarkTest5()
196 {
197  ito::DataObject *do1 = NULL; //new ito::DataObject(10000,100,100,ito::tFloat32);
198  ito::DataObject *do2 = NULL;//new ito::DataObject(*do1);
199 
200  qDebug("benchmarkTest5");
201  int64 start, ende;
202  double freq = cv::getTickFrequency();
203  size_t j = 0;
204 
205  start = cv::getTickCount();
206  for (size_t i = 0 ; i < 1000000; i++)
207  {
208  j += i;
209  }
210  ende = cv::getTickCount();
211  qDebug() << "time: " << (ende-start)/freq;
212 
213  j = 0;
214  start = cv::getTickCount();
215  for (size_t i = 0 ; i < 1000000; ++i)
216  {
217  j += i;
218  }
219  ende = cv::getTickCount();
220  qDebug() << "time: " << (ende-start)/freq;
221 };
222 
223 typedef struct
224 {
225  union
226  {
227  union
228  {
229  struct
230  {
231  ito::uint8 b;
232  ito::uint8 g;
233  ito::uint8 r;
234  ito::uint8 a;
235  };
236  float rgb;
237  };
238  ito::uint32 rgba;
239  };
240 
241 }
242 rgba32_;
243 
244 void benchmarkTestColor()
245 {
246  int64 start, ende;
247  double freq = cv::getTickFrequency();
248  size_t j = 0;
249 
250  ito::Rgba32 c1, c2;
251 
252  start = cv::getTickCount();
253  for (size_t i = 0 ; i < 1000000; i++)
254  {
255  ito::Rgba32 e1;
256  }
257  ende = cv::getTickCount();
258  qDebug() << "time: " << (ende-start)/freq;
259 
260  start = cv::getTickCount();
261  for (size_t i = 0 ; i < 1000000; i++)
262  {
263  c1 = ito::Rgba32(12,13,14,15);
264  }
265  ende = cv::getTickCount();
266  qDebug() << "time: " << (ende-start)/freq;
267 
268  start = cv::getTickCount();
269  for (size_t i = 0 ; i < 1000000; i++)
270  {
271  c2 = c1;
272  }
273  ende = cv::getTickCount();
274  qDebug() << "time: " << (ende-start)/freq;
275 
276  for (size_t i = 0 ; i < 1000000; i++)
277  {
278  unsigned int argb = c2.argb();
279  argb = argb+2;
280  }
281  ende = cv::getTickCount();
282  qDebug() << "time: " << (ende-start)/freq;
283 
284 
285 
286  start = cv::getTickCount();
287  for (size_t i = 0 ; i < 1000000; i++)
288  {
289  rgba32_ e1;
290  }
291  ende = cv::getTickCount();
292  qDebug() << "time: " << (ende-start)/freq;
293 
294  rgba32_ d1, d2;
295  start = cv::getTickCount();
296  for (size_t i = 0 ; i < 1000000; i++)
297  {
298  d1.r = 13;
299  d1.a = 12;
300  d1.g = 14;
301  d1.b = 15;
302  }
303  ende = cv::getTickCount();
304  qDebug() << "time: " << (ende-start)/freq;
305 
306  start = cv::getTickCount();
307 
308  for (size_t i = 0 ; i < 1000000; i++)
309  {
310  d2 = d1;
311  }
312  ende = cv::getTickCount();
313  qDebug() << "time: " << (ende-start)/freq;
314 
315  start = cv::getTickCount();
316  for (size_t i = 0 ; i < 1000000; i++)
317  {
318  unsigned int argb = d2.rgba;
319  argb = argb+2;
320  }
321  ende = cv::getTickCount();
322  qDebug() << "time: " << (ende-start)/freq;
323 
324 
325  qDebug() << "array construction";
326  start = cv::getTickCount();
327  ito::Rgba32 h1[100000];
328  ende = cv::getTickCount();
329  qDebug() << "time: " << (ende-start)/freq;
330 
331  start = cv::getTickCount();
332  rgba32_ h2[100000];
333  ende = cv::getTickCount();
334  qDebug() << "time: " << (ende-start)/freq;
335 
336  start = cv::getTickCount();
337  ito::uint32 h3[100000];
338  ende = cv::getTickCount();
339  qDebug() << "time: " << (ende-start)/freq;
340 }
341 
342 void dataObjectDStackMemoryLeak()
343 {
344  for (int i = 0; i < 100; ++i)
345  {
346  qDebug() << "round " << i;
347  int n = 50;
348  ito::DataObject *mats = new ito::DataObject[n];
349  for (int i = 0; i < n; ++i)
350  {
351  mats[i] = ito::DataObject(1000,1000, ito::tFloat64);
352  }
353 
354  {
355  ito::DataObject result = ito::DataObject::stack(mats, n);
356 
357  delete[] mats;
358  mats = NULL;
359  }
360 
361  qDebug() << "round " << i << " finished";
362  }
363 
364 }
365 
366 
367 void startBenchmarks()
368 {
369  benchmarkTest1();
370  benchmarkTest2();
371  benchmarkTest3();
372  benchmarkTest4();
373  benchmarkTest5();
374  benchmarkTestColor();
375 }
376 
377 #endif
378 
379 
380 
381 
382 
383 
384 
385 
dataObject contains a n-dimensional matrix
Definition: dataobj.h:511
Definition: typeDefs.h:96
uint32 & argb()
Definition: color.h:250
Definition: typeDefs.h:95
Definition: benchmarks.h:223
This class implements basic functionality for color handling in itom. This class implements ARGB32 i...
Definition: color.h:46
static DataObject stack(const DataObject *mats, int num, unsigned int axis=0)
returns a stack of multiple dataObjects (number is equal to num) along the given axis (default: 0)...
Definition: dataobj.cpp:7813