/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ### File Specific: main-programmer: Patrick Boenzli co-programmer: ... */ #if defined __linux__ #include "list.h" #include "world_entity.h" #include "vector.h" #include "player.h" #include "base_object.h" #include #include #define LIST_MAX 1000 #define VECTOR_MAX 1000000 #define ITERATIONS 10000 int startBenchmarks() { printf("===========================================================\n"); printf("= BENCHMARKS =\n"); printf("===========================================================\n"); printf(" the author is not paying any attention to cacheing effects\n"); printf(" of the CPU.\n\n"); printf("[title]\t\t\t\t\t [cycles]\t[loops]\n\n"); // printf("------------------------------------------------------------\n\n"); // first measure the time overhead: unsigned long ini, end, dt, tmp; rdtscl(ini); rdtscl(end); dt = end - ini; int type = -1; /* type -1 == all type 0 == framework type 1 == vector type 2 == quaternion type 3 == lists */ if(type == 0 || type == -1) { /* framework test*/ printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS); /* ************WorldEntity class test************** */ WorldEntity* w = NULL; int i = 0; unsigned long mittel = 0; for(i = 0; i < ITERATIONS; ++i) { rdtscl(ini); WorldEntity* w = new WorldEntity(); rdtscl(end); delete w; mittel += (end - ini - dt); } float mi = mittel / (float)ITERATIONS; printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi); /* mittel = 0; for(i = 0; i < ITERATIONS; ++i) { rdtscl(ini); WorldEntity* w = new Primitive(P_SPHERE); rdtscl(end); delete w; mittel += (end - ini - dt); } mi = mittel / (float)ITERATIONS; printf(" Generate a Primitive object:\t\t%11.2f\n", mi); */ mittel = 0; for(i = 0; i < ITERATIONS; ++i) { rdtscl(ini); Vector* v = new Vector(); rdtscl(end); delete v; mittel += (end - ini - dt); } mi = mittel / (float)ITERATIONS; printf(" Generate a Vector object:\t\t%11.2f\n", mi); mittel = 0; for(i = 0; i < ITERATIONS; ++i) { rdtscl(ini); Quaternion* q = new Quaternion(); rdtscl(end); delete q; mittel += (end - ini - dt); } mi = mittel / (float)ITERATIONS; printf(" Generate a Quaternion object:\t\t%11.2f\n", mi); printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS); mittel = 0; w = new WorldEntity(); for(i = 0; i < ITERATIONS; ++i) { rdtscl(ini); w->tick(0.0f); rdtscl(end); mittel += (end - ini - dt); } //delete w; mi = mittel / (float)ITERATIONS; printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi); mittel = 0; WorldEntity wo; for(i = 0; i < ITERATIONS; ++i) { rdtscl(ini); wo.tick(0.0f); rdtscl(end); mittel += (end - ini - dt); } //delete w; mi = mittel / (float)ITERATIONS; printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi); mittel = 0; BaseObject* bo = new BaseObject(); for(i = 0; i < ITERATIONS; ++i) { rdtscl(ini); // bo->isFinalized(); rdtscl(end); mittel += (end - ini - dt); } //delete w; mi = mittel / (float)ITERATIONS; printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi); tList* list = new tList(); /* ************Primitvie class test************** */ list = new tList(); /* mittel = 0; w = new Primitive(P_SPHERE); for(i = 0; i < ITERATIONS; ++i) { rdtscl(ini); w->tick(0.0f); rdtscl(end); mittel += (end - ini - dt); } mi = mittel / (float)ITERATIONS; printf(" Call function tick() of Prim:\t\t%11.2f\n", mi); */ } if(type == 1 || type == -1) { printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX); /* vector test */ Vector* a = new Vector(1.3, 5.3, 4.1); Vector* b = new Vector(0.4, 2.5, 6.2); Vector* c = new Vector(); unsigned long mittel, ini, end; float mi; int i = 0; // addition mittel = 0; for(i = 0; i < VECTOR_MAX; ++i) { rdtscl(ini); *c = *a + *b; rdtscl(end); mittel += (end - ini - dt); } mi = mittel / (float)VECTOR_MAX; printf(" Addition of two vectors:\t\t%11.2f\n", mi); // multiplikation mittel = 0; for(i = 0; i < VECTOR_MAX; ++i) { rdtscl(ini); *c = a->cross( *b); rdtscl(end); mittel += (end - ini - dt); } mi = mittel / (float)VECTOR_MAX; printf(" CrossMult of two vectors:\t\t%11.2f\n", mi); } if( type == 2 || type == -1) { /* quaternion test */ printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX); /* vector test */ Quaternion* a = new Quaternion(); Quaternion* b = new Quaternion(); Quaternion* c = new Quaternion(); unsigned long mittel, ini, end; float mi; int i = 0; // quaternion generieren mit spez konstruktor mittel = 0; Vector* qa = new Vector(4.6, 9.3, 0.4); Vector* qb = new Vector(3.5, 6.1, 4.3); for(i = 0; i < VECTOR_MAX; ++i) { rdtscl(ini); Quaternion* qu = new Quaternion(*qa, *qb); rdtscl(end); delete qu; mittel += (end - ini - dt); } delete a; delete b; mi = mittel / (float)VECTOR_MAX; printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi); // multiplication mittel = 0; for(i = 0; i < VECTOR_MAX; ++i) { rdtscl(ini); *c = *a * *b; rdtscl(end); mittel += (end - ini - dt); } mi = mittel / (float)VECTOR_MAX; printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi); // rotating a vector by a quaternion mittel = 0; for(i = 0; i < VECTOR_MAX; ++i) { rdtscl(ini); *qa = a->apply(*qb); rdtscl(end); mittel += (end - ini - dt); } mi = mittel / (float)VECTOR_MAX; printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi); // generate rotation matrix mittel = 0; float matrix[4][4]; for(i = 0; i < VECTOR_MAX; ++i) { rdtscl(ini); a->matrix(matrix); rdtscl(end); mittel += (end - ini - dt); } mi = mittel / (float)VECTOR_MAX; printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi); } if( type == 3 || type == -1) { /* list tests*/ printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); tList* list = new tList(); char* name; printf(" Adding[1..10] elements to list, found:\n"); list->add("1"); list->add("2"); list->add("3"); list->add("4"); list->add("5"); list->add("6"); list->add("7"); list->add("8"); list->add("9"); list->add("10"); /*give list out */ tIterator* iterator = list->getIterator(); name = iterator->nextElement(); printf(" List Elements: \t\t"); while( name != NULL) { printf("%s,", name); name = iterator->nextElement(); } delete iterator; printf("\n"); /*removing some elements from the list*/ printf(" Removing elements [2,3,6,8,10], adding [11] now found:\n"); list->remove("2"); list->remove("3"); list->remove("6"); list->remove("8"); list->remove("10"); list->add("11"); /*give list out */ iterator = list->getIterator(); name = iterator->nextElement(); printf(" List Elements: \t\t"); while( name != NULL) { printf("%s,", name); name = iterator->nextElement(); } delete iterator; printf("\n"); delete list; printf("\nChecking list performance:\t\t\t\t%i\n", LIST_MAX); tList* plist = new tList(); unsigned long mittel, ini, end; float mi; int i = 0; mittel = 0; for(i = 0; i < LIST_MAX; ++i) { rdtscl(ini); plist->add(&i); rdtscl(end); mittel += (end - ini - dt); } mi = mittel / (float)LIST_MAX; printf(" Adding reference to list:\t\t%11.2f\n", mi); mittel = 0; for(i = 0; i < LIST_MAX; ++i) { rdtscl(ini); plist->remove(&i); rdtscl(end); mittel += (end - ini - dt); } mi = mittel / (float)LIST_MAX; printf(" Removing 1st reference from list:\t%11.2f\n", mi); printf("\nList operations tests: \t\t\t\t\t%i\n", LIST_MAX); list = new tList(); printf(" Adding[1..10] elements to list, found:\n"); list->add("1"); list->add("2"); list->add("3"); list->add("4"); list->add("5"); list->add("6"); list->add("7"); list->add("8"); list->add("9"); list->add("10"); /*give list out */ iterator = list->getIterator(); name = iterator->nextElement(); printf(" List Elements: \t\t"); while( name != NULL) { printf("%s,", name); name = iterator->nextElement(); } delete iterator; printf("\n"); int c = 0; printf(" Going trough list with nextElement(el) func: "); name = list->firstElement(); while(c < 20) { printf("%s,", name); name = list->nextElement(name); c++; } printf("\n"); } } #else #include "debug.h" int startBenchmarks() { PRINTF(1)("Benchmark is not implemented in this system\n"); } #endif