summaryrefslogtreecommitdiff
path: root/tools/container_test.cpp
diff options
context:
space:
mode:
authorsaurabhb172020-02-26 16:40:14 +0530
committerGitHub2020-02-26 16:40:14 +0530
commit02c614b4e64b68758f223391cb5357b3eec78cac (patch)
treead18839d8b4eb1f13419d07878cc4ec4c9b70032 /tools/container_test.cpp
parentb77f5d9d8097c38159c6f60917995d6af13bbe1c (diff)
parent07a8c86216b6b1f694b136ec64c281d62941952e (diff)
downloadKiCad-eSim-02c614b4e64b68758f223391cb5357b3eec78cac.tar.gz
KiCad-eSim-02c614b4e64b68758f223391cb5357b3eec78cac.tar.bz2
KiCad-eSim-02c614b4e64b68758f223391cb5357b3eec78cac.zip
Merge pull request #6 from saurabhb17/master
minor additions
Diffstat (limited to 'tools/container_test.cpp')
-rw-r--r--tools/container_test.cpp132
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();
+}