Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9406 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

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 <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;
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      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->firstElement();
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->firstElement();
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->firstElement();
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    return 0;
459}
460
461#else
462
463#include "debug.h"
464
465int startBenchmarks()
466{
467  PRINTF(1)("Benchmark is not implemented in this system\n");
468}
469
470#endif
Note: See TracBrowser for help on using the repository browser.