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
RevLine 
[9669]1#include "new_class_id.h"
2#include "new_object_list.h"
3#include <iostream>
4
[9674]5#include <base_object.h>
6
7class NewBaseObject
[9669]8{
[9673]9public:
10  void setName(const std::string& name) { this->_objectName = name; };
[9674]11  const std::string& getName() const { return _objectName; };
[9671]12  bool operator==(const std::string& name) const { return _objectName == name; };
13
[9674]14  NewObjectListDeclaration(NewBaseObject);
[9672]15
[9671]16protected:
[9674]17  NewBaseObject(const std::string& objectName = "") : _objectName(objectName)
18  {
19    this->registerObject(this, objectList);
20  };
[9671]21  template<class T>
[9673]22  inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); };
23private:
[9671]24  NewClassID    _id;
25  std::string   _objectName;
26
[9672]27
[9671]28};
[9674]29NewObjectListDefinition(NewBaseObject);
[9671]30
[9672]31
[9674]32class Test : public NewBaseObject
[9671]33{
[9669]34public:
35  Test();
36  ~Test();
37
38
39  NewObjectListDeclaration(Test);
40  //ObjectListDeclaration(Test);
41};
42NewObjectListDefinition(Test);
43
44Test::Test()
[9671]45{
[9674]46//  this->setClassID(CL_PARENT_NODE, "Test");
[9671]47  this->registerObject(this, Test::objectList);
[9674]48  // std::cout << "Test()\n";
[9671]49};
[9669]50Test::~Test()
[9673]51{
[9674]52  //  std::cout << "~Test()\n";
[9673]53}
[9669]54
[9671]55class Bone : public BaseObject
[9669]56{
57public:
[9673]58  Bone()
59  {
[9674]60//    this->registerObject(this, Bone::objectList);
[9673]61    //std::cout << "Bone()\n";
62  };
[9674]63  ~Bone()
64  {
65    //  std::cout << "~Bone()\n";
[9673]66  };
[9669]67  NewObjectListDeclaration(Bone);
68};
69NewObjectListDefinition(Bone);
70
71int main()
72{
[9674]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();
[9669]94
95}
96
Note: See TracBrowser for help on using the repository browser.