You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
2.5 KiB

  1. #include <base_struct.h>
  2. #include <boost/ptr_container/ptr_vector.hpp>
  3. #include <deque>
  4. #include <dlist.h>
  5. #include <time.h>
  6. #include <common.h>
  7. #define TEST_NODES 100000000
  8. //typedef std::vector<EDA_ITEM*> EDA_ITEMV;
  9. //typedef std::deque<EDA_ITEM*> EDA_ITEMV;
  10. typedef boost::ptr_vector<EDA_ITEM> EDA_ITEMV;
  11. class MY_ITEM : public EDA_ITEM
  12. {
  13. public:
  14. MY_ITEM( KICAD_T id ) :
  15. EDA_ITEM( id )
  16. {}
  17. #if defined(DEBUG)
  18. void Show( int nestLevel, std::ostream& os ) const
  19. {
  20. ShowDummy( os );
  21. }
  22. #endif
  23. };
  24. void heap_warm_up();
  25. int main( int argc, char** argv )
  26. {
  27. EDA_ITEMV v;
  28. DLIST<EDA_ITEM> dlist;
  29. unsigned vAllocStart;
  30. unsigned vAllocStop;
  31. unsigned vIterateStart;
  32. unsigned vIterateStop;
  33. unsigned dAllocStart;
  34. unsigned dAllocStop;
  35. unsigned dIterateStart;
  36. unsigned dIterateStop;
  37. heap_warm_up();
  38. vAllocStart = GetRunningMicroSecs();
  39. for( int i=0; i<TEST_NODES; ++i )
  40. {
  41. v.push_back( new MY_ITEM( NOT_USED ) );
  42. }
  43. vAllocStop = GetRunningMicroSecs();
  44. vIterateStart = vAllocStop;
  45. for( EDA_ITEMV::const_iterator it = v.begin(); it != v.end(); ++it )
  46. {
  47. if( it->Type() == -22 )
  48. {
  49. printf( "never this\n" );
  50. break;
  51. }
  52. }
  53. vIterateStop = GetRunningMicroSecs();
  54. #if 0
  55. for( int i=0; i<TEST_NODES; ++i )
  56. {
  57. delete v[i];
  58. }
  59. #endif
  60. v.clear();
  61. dAllocStart = GetRunningMicroSecs();
  62. for( int i=0; i<TEST_NODES; ++i )
  63. {
  64. dlist.PushBack( new MY_ITEM( NOT_USED ) );
  65. }
  66. dAllocStop = GetRunningMicroSecs();
  67. dIterateStart = dAllocStop;
  68. for( const EDA_ITEM* it = dlist; it; it = it->Next() )
  69. {
  70. if( it->Type() == -22 )
  71. {
  72. printf( "never this\n" );
  73. break;
  74. }
  75. }
  76. dIterateStop = GetRunningMicroSecs();
  77. printf( "vector alloc: %u usecs iterate: %u usecs\n",
  78. vAllocStop - vAllocStart,
  79. vIterateStop - vIterateStart );
  80. printf( "dlist alloc: %u usecs iterate: %u usecs\n",
  81. dAllocStop - dAllocStart,
  82. dIterateStop - dIterateStart );
  83. }
  84. void heap_warm_up()
  85. {
  86. // dry run allocate enough object for process to obtain all memory needed
  87. EDA_ITEMV vec;
  88. for( int i=0; i<TEST_NODES; ++i )
  89. {
  90. vec.push_back( new MY_ITEM( NOT_USED ) );
  91. }
  92. for( int i=0; i<TEST_NODES; ++i )
  93. {
  94. // delete vec[i];
  95. }
  96. vec.clear();
  97. }