Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/lang/test_object_list.cc @ 9674

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

orxonox/trunk: here is the speedup test… more or less:
20 iterations of generating and deleting 10000 objects

old version:
real 0m7.485s
user 0m7.344s
sys 0m0.012s

new version:
real 0m0.627s
user 0m0.568s
sys 0m0.032s

for that it is way more dynamic, the speedup was worth it :)

File size: 1.9 KB
Line 
1#include "new_class_id.h"
2#include "new_object_list.h"
3#include <iostream>
4
5#include <base_object.h>
6
7class NewBaseObject
8{
9public:
10  void setName(const std::string& name) { this->_objectName = name; };
11  const std::string& getName() const { return _objectName; };
12  bool operator==(const std::string& name) const { return _objectName == name; };
13
14  NewObjectListDeclaration(NewBaseObject);
15
16protected:
17  NewBaseObject(const std::string& objectName = "") : _objectName(objectName)
18  {
19    this->registerObject(this, objectList);
20  };
21  template<class T>
22  inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); };
23private:
24  NewClassID    _id;
25  std::string   _objectName;
26
27
28};
29NewObjectListDefinition(NewBaseObject);
30
31
32class Test : public NewBaseObject
33{
34public:
35  Test();
36  ~Test();
37
38
39  NewObjectListDeclaration(Test);
40  //ObjectListDeclaration(Test);
41};
42NewObjectListDefinition(Test);
43
44Test::Test()
45{
46//  this->setClassID(CL_PARENT_NODE, "Test");
47  this->registerObject(this, Test::objectList);
48  // std::cout << "Test()\n";
49};
50Test::~Test()
51{
52  //  std::cout << "~Test()\n";
53}
54
55class Bone : public BaseObject
56{
57public:
58  Bone()
59  {
60//    this->registerObject(this, Bone::objectList);
61    //std::cout << "Bone()\n";
62  };
63  ~Bone()
64  {
65    //  std::cout << "~Bone()\n";
66  };
67  NewObjectListDeclaration(Bone);
68};
69NewObjectListDefinition(Bone);
70
71int main()
72{
73  for (unsigned int i = 0; i < 20; ++i)
74  {
75    std::cout<< i << std::endl;
76    Test* test = new Test[10000];
77    delete[]test;
78  }
79  //   char tmp[100];
80  //   for (unsigned int i = 0 ; i < 100; ++i)
81  //   {
82  //     sprintf(tmp, "Tmp_%d", i);
83  //     test[i].setName(tmp);
84  //   }
85  //   Test::objectList.debug();
86  //   //test->setName("Test-object");
87  //
88  //   std::cout << "Here is debug of all BaseObject\n";
89  //   BaseObject::objectList.debug();
90  // //   delete bone;
91  //   delete []test;
92  //   std::cout << "Again\n";
93  //   BaseObject::objectList.debug();
94
95}
96
Note: See TracBrowser for help on using the repository browser.