diff options
author | saurabhb17 | 2020-02-26 16:37:17 +0530 |
---|---|---|
committer | GitHub | 2020-02-26 16:37:17 +0530 |
commit | 07a8c86216b6b1f694b136ec64c281d62941952e (patch) | |
tree | ad18839d8b4eb1f13419d07878cc4ec4c9b70032 /tools/container_test.cpp | |
parent | e255d0622297488c1c52755be670733418c994cf (diff) | |
parent | 1fa449fed953fa11f6bd0ea82cc2d3b115ee0781 (diff) | |
download | KiCad-eSim-07a8c86216b6b1f694b136ec64c281d62941952e.tar.gz KiCad-eSim-07a8c86216b6b1f694b136ec64c281d62941952e.tar.bz2 KiCad-eSim-07a8c86216b6b1f694b136ec64c281d62941952e.zip |
Merge pull request #2 from saurabhb17/develop
Remaining files transfered
Diffstat (limited to 'tools/container_test.cpp')
-rw-r--r-- | tools/container_test.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/tools/container_test.cpp b/tools/container_test.cpp new file mode 100644 index 0000000..3b65dad --- /dev/null +++ b/tools/container_test.cpp @@ -0,0 +1,132 @@ + +#include <base_struct.h> +#include <boost/ptr_container/ptr_vector.hpp> +#include <deque> +#include <dlist.h> +#include <time.h> +#include <common.h> + +#define TEST_NODES 100000000 + + +//typedef std::vector<EDA_ITEM*> EDA_ITEMV; +//typedef std::deque<EDA_ITEM*> EDA_ITEMV; +typedef boost::ptr_vector<EDA_ITEM> EDA_ITEMV; + +class MY_ITEM : public EDA_ITEM +{ +public: + + MY_ITEM( KICAD_T id ) : + EDA_ITEM( id ) + {} + + +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ) const + { + ShowDummy( os ); + } +#endif +}; + + +void heap_warm_up(); + +int main( int argc, char** argv ) +{ + EDA_ITEMV v; + DLIST<EDA_ITEM> dlist; + + unsigned vAllocStart; + unsigned vAllocStop; + unsigned vIterateStart; + unsigned vIterateStop; + + unsigned dAllocStart; + unsigned dAllocStop; + unsigned dIterateStart; + unsigned dIterateStop; + + heap_warm_up(); + + vAllocStart = GetRunningMicroSecs(); + + for( int i=0; i<TEST_NODES; ++i ) + { + v.push_back( new MY_ITEM( NOT_USED ) ); + } + + vAllocStop = GetRunningMicroSecs(); + vIterateStart = vAllocStop; + + for( EDA_ITEMV::const_iterator it = v.begin(); it != v.end(); ++it ) + { + if( it->Type() == -22 ) + { + printf( "never this\n" ); + break; + } + } + + vIterateStop = GetRunningMicroSecs(); + +#if 0 + for( int i=0; i<TEST_NODES; ++i ) + { + delete v[i]; + } +#endif + + v.clear(); + + + dAllocStart = GetRunningMicroSecs(); + + for( int i=0; i<TEST_NODES; ++i ) + { + dlist.PushBack( new MY_ITEM( NOT_USED ) ); + } + + dAllocStop = GetRunningMicroSecs(); + dIterateStart = dAllocStop; + + for( const EDA_ITEM* it = dlist; it; it = it->Next() ) + { + if( it->Type() == -22 ) + { + printf( "never this\n" ); + break; + } + } + + dIterateStop = GetRunningMicroSecs(); + + printf( "vector alloc: %u usecs iterate: %u usecs\n", + vAllocStop - vAllocStart, + vIterateStop - vIterateStart ); + + printf( "dlist alloc: %u usecs iterate: %u usecs\n", + dAllocStop - dAllocStart, + dIterateStop - dIterateStart ); +} + + +void heap_warm_up() +{ + // dry run allocate enough object for process to obtain all memory needed + + EDA_ITEMV vec; + + for( int i=0; i<TEST_NODES; ++i ) + { + vec.push_back( new MY_ITEM( NOT_USED ) ); + } + + for( int i=0; i<TEST_NODES; ++i ) + { + // delete vec[i]; + } + + vec.clear(); +} |