Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: reverted the last steps, because they created a huge pack of seg-faults

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