Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/subprojects/benchmark.cc @ 5427

Last change on this file since 5427 was 5427, checked in by bensch, 19 years ago

orxonox/trunk: some minor include stuff

File size: 11.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software Foundation,
18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20
21   ### File Specific:
22   main-programmer: Patrick Boenzli
23   co-programmer: ...
24
25*/
26
27
28#if defined __linux__
29
30#include "list.h"
31#include "world_entity.h"
32#include "vector.h"
33#include "player.h"
34#include "base_object.h"
35
36#include <stdlib.h>
37#include <asm/msr.h>
38#include <linux/timex.h>
39
40
41#define LIST_MAX 1000
42#define VECTOR_MAX 1000000
43#define ITERATIONS 10000
44
45
46int startBenchmarks()
47{
48
49  printf("===========================================================\n");
50  printf("=                      BENCHMARKS                         =\n");
51  printf("===========================================================\n");
52  printf(" the author is not paying any attention to cacheing effects\n");
53  printf(" of the CPU.\n\n");
54  printf("[title]\t\t\t\t\t     [cycles]\t[loops]\n\n");
55  //  printf("------------------------------------------------------------\n\n");
56
57  // first measure the time overhead:
58  unsigned long ini, end, dt, tmp;
59  rdtscl(ini); rdtscl(end);
60  dt = end - ini;
61
62  int type = -1;
63  /* type   -1 == all
64     type    0 == framework
65     type    1 == vector
66     type    2 == quaternion
67     type    3 == lists
68  */
69  if(type == 0 || type == -1)
70    {
71      /* framework test*/
72
73      printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS);
74      /* ************WorldEntity class test************** */
75      WorldEntity* w = NULL;
76      int i = 0;
77      unsigned long mittel = 0;
78
79      for(i = 0; i < ITERATIONS; ++i)
80        {
81          rdtscl(ini);
82
83          WorldEntity* w = new WorldEntity();
84
85          rdtscl(end);
86          delete w;
87          mittel += (end - ini - dt);
88        }
89      float mi = mittel / (float)ITERATIONS;
90      printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi);
91
92      /*
93        mittel = 0;
94        for(i = 0; i < ITERATIONS; ++i)
95        {
96        rdtscl(ini);
97
98        WorldEntity* w = new Primitive(P_SPHERE);
99
100        rdtscl(end);
101        delete w;
102        mittel += (end - ini - dt);
103        }
104        mi = mittel / (float)ITERATIONS;
105        printf(" Generate a Primitive  object:\t\t%11.2f\n", mi);
106      */
107
108      mittel = 0;
109      for(i = 0; i < ITERATIONS; ++i)
110        {
111          rdtscl(ini);
112
113          Vector* v = new Vector();
114
115          rdtscl(end);
116          delete v;
117          mittel += (end - ini - dt);
118        }
119      mi = mittel / (float)ITERATIONS;
120      printf(" Generate a Vector object:\t\t%11.2f\n", mi);
121
122
123     mittel = 0;
124      for(i = 0; i < ITERATIONS; ++i)
125        {
126          rdtscl(ini);
127
128          Quaternion* q = new Quaternion();
129
130          rdtscl(end);
131          delete q;
132          mittel += (end - ini - dt);
133        }
134      mi = mittel / (float)ITERATIONS;
135      printf(" Generate a Quaternion object:\t\t%11.2f\n", mi);
136
137
138
139
140      printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS);
141      mittel = 0;
142      w = new WorldEntity();
143      for(i = 0; i < ITERATIONS; ++i)
144        {
145          rdtscl(ini);
146
147          w->tick(0.0f);
148
149          rdtscl(end);
150          mittel += (end - ini - dt);
151          }
152      //delete w;
153      mi = mittel / (float)ITERATIONS;
154      printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi);
155
156
157      mittel = 0;
158      WorldEntity wo;
159      for(i = 0; i < ITERATIONS; ++i)
160        {
161          rdtscl(ini);
162
163          wo.tick(0.0f);
164
165          rdtscl(end);
166          mittel += (end - ini - dt);
167          }
168      //delete w;
169      mi = mittel / (float)ITERATIONS;
170      printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi);
171
172
173      mittel = 0;
174      BaseObject* bo = new BaseObject();
175      for(i = 0; i < ITERATIONS; ++i)
176        {
177          rdtscl(ini);
178
179//          bo->isFinalized();
180
181          rdtscl(end);
182          mittel += (end - ini - dt);
183          }
184      //delete w;
185      mi = mittel / (float)ITERATIONS;
186      printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi);
187
188
189      tList<WorldEntity>* list = new tList<WorldEntity>();
190
191
192      /* ************Primitvie class test************** */
193      list = new tList<WorldEntity>();
194
195
196      /*
197        mittel = 0;
198        w = new Primitive(P_SPHERE);
199        for(i = 0; i < ITERATIONS; ++i)
200        {
201        rdtscl(ini);
202
203        w->tick(0.0f);
204
205        rdtscl(end);
206        mittel += (end - ini - dt);
207        }
208        mi = mittel / (float)ITERATIONS;
209        printf(" Call function tick() of Prim:\t\t%11.2f\n", mi);
210      */
211
212    }
213
214  if(type == 1 || type == -1)
215    {
216      printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX);
217      /* vector test */
218      Vector* a = new Vector(1.3, 5.3, 4.1);
219      Vector* b = new Vector(0.4, 2.5, 6.2);
220      Vector* c = new Vector();
221
222      unsigned long mittel, ini, end;
223      float mi;
224      int i = 0;
225      // addition
226      mittel = 0;
227      for(i = 0; i < VECTOR_MAX; ++i)
228        {
229          rdtscl(ini);
230
231          *c = *a + *b;
232
233          rdtscl(end);
234          mittel += (end - ini - dt);
235        }
236      mi = mittel / (float)VECTOR_MAX;
237      printf(" Addition of two vectors:\t\t%11.2f\n", mi);
238
239      // multiplikation
240
241      mittel = 0;
242      for(i = 0; i < VECTOR_MAX; ++i)
243        {
244          rdtscl(ini);
245
246          *c = a->cross( *b);
247
248          rdtscl(end);
249          mittel += (end - ini - dt);
250        }
251      mi = mittel / (float)VECTOR_MAX;
252      printf(" CrossMult of two vectors:\t\t%11.2f\n", mi);
253
254    }
255  if( type == 2 || type == -1)
256    {
257      /* quaternion test */
258      printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX);
259      /* vector test */
260      Quaternion* a = new Quaternion();
261      Quaternion* b = new Quaternion();
262      Quaternion* c = new Quaternion();
263
264      unsigned long mittel, ini, end;
265      float mi;
266      int i = 0;
267      // quaternion generieren mit spez konstruktor
268      mittel = 0;
269      Vector* qa = new Vector(4.6, 9.3, 0.4);
270      Vector* qb = new Vector(3.5, 6.1, 4.3);
271      for(i = 0; i < VECTOR_MAX; ++i)
272        {
273          rdtscl(ini);
274
275          Quaternion* qu = new Quaternion(*qa, *qb);
276
277          rdtscl(end);
278          delete qu;
279          mittel += (end - ini - dt);
280        }
281      delete a;
282      delete b;
283      mi = mittel / (float)VECTOR_MAX;
284      printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi);
285
286
287      // multiplication
288      mittel = 0;
289      for(i = 0; i < VECTOR_MAX; ++i)
290        {
291          rdtscl(ini);
292
293          *c = *a * *b;
294
295          rdtscl(end);
296          mittel += (end - ini - dt);
297        }
298      mi = mittel / (float)VECTOR_MAX;
299      printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi);
300
301
302
303      // rotating a vector by a quaternion
304      mittel = 0;
305      for(i = 0; i < VECTOR_MAX; ++i)
306        {
307          rdtscl(ini);
308
309          *qa = a->apply(*qb);
310
311          rdtscl(end);
312          mittel += (end - ini - dt);
313        }
314      mi = mittel / (float)VECTOR_MAX;
315      printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi);
316
317
318
319      // generate rotation matrix
320      mittel = 0;
321      float matrix[4][4];
322      for(i = 0; i < VECTOR_MAX; ++i)
323        {
324          rdtscl(ini);
325
326          a->matrix(matrix);
327
328          rdtscl(end);
329          mittel += (end - ini - dt);
330        }
331      mi = mittel / (float)VECTOR_MAX;
332      printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi);
333    }
334  if( type == 3 || type == -1)
335    {
336      /* list tests*/
337      printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX);
338      tList<char>* list = new tList<char>();
339      char* name;
340
341      printf(" Adding[1..10] elements to list, found:\n");
342      list->add("1");
343      list->add("2");
344      list->add("3");
345      list->add("4");
346      list->add("5");
347      list->add("6");
348      list->add("7");
349      list->add("8");
350      list->add("9");
351      list->add("10");
352
353      /*give list out */
354      tIterator<char>* iterator = list->getIterator();
355      name = iterator->firstElement();
356      printf("  List Elements: \t\t");
357      while( name != NULL)
358        {
359          printf("%s,", name);
360          name = iterator->nextElement();
361        }
362      delete iterator;
363      printf("\n");
364
365
366      /*removing some elements from the list*/
367      printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n");
368      list->remove("2");
369      list->remove("3");
370      list->remove("6");
371      list->remove("8");
372      list->remove("10");
373      list->add("11");
374      /*give list out */
375      iterator = list->getIterator();
376      name = iterator->firstElement();
377      printf("  List Elements: \t\t");
378      while( name != NULL)
379        {
380          printf("%s,", name);
381          name = iterator->nextElement();
382        }
383      delete iterator;
384      printf("\n");
385
386      delete list;
387      printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX);
388
389      tList<int>* plist = new tList<int>();
390      unsigned long mittel, ini, end;
391      float mi;
392      int i = 0;
393      mittel = 0;
394      for(i = 0; i < LIST_MAX; ++i)
395        {
396          rdtscl(ini);
397
398          plist->add(&i);
399
400          rdtscl(end);
401          mittel += (end - ini - dt);
402        }
403      mi = mittel / (float)LIST_MAX;
404      printf(" Adding reference to list:\t\t%11.2f\n", mi);
405
406      mittel = 0;
407      for(i = 0; i < LIST_MAX; ++i)
408        {
409          rdtscl(ini);
410
411          plist->remove(&i);
412
413          rdtscl(end);
414          mittel += (end - ini - dt);
415        }
416      mi = mittel / (float)LIST_MAX;
417      printf(" Removing 1st reference from list:\t%11.2f\n", mi);
418
419
420      printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX);
421      list = new tList<char>();
422      printf(" Adding[1..10] elements to list, found:\n");
423      list->add("1");
424      list->add("2");
425      list->add("3");
426      list->add("4");
427      list->add("5");
428      list->add("6");
429      list->add("7");
430      list->add("8");
431      list->add("9");
432      list->add("10");
433
434      /*give list out */
435      iterator = list->getIterator();
436      name = iterator->firstElement();
437      printf("  List Elements: \t\t");
438      while( name != NULL)
439        {
440          printf("%s,", name);
441          name = iterator->nextElement();
442        }
443      delete iterator;
444      printf("\n");
445
446
447      int c = 0;
448      printf(" Going trough list with nextElement(el) func: ");
449      name = list->firstElement();
450      while(c < 20)
451        {
452          printf("%s,", name);
453          name = list->nextElement(name);
454          c++;
455        }
456      printf("\n");
457
458
459
460    }
461
462}
463
464#else
465
466#include "debug.h"
467
468int startBenchmarks()
469{
470  PRINTF(1)("Benchmark is not implemented in this system\n");
471}
472
473#endif
Note: See TracBrowser for help on using the repository browser.