Boost logo

Boost-Commit :

From: xushiweizh_at_[hidden]
Date: 2008-05-07 01:22:10


Author: xushiwei
Date: 2008-05-07 01:22:09 EDT (Wed, 07 May 2008)
New Revision: 45189
URL: http://svn.boost.org/trac/boost/changeset/45189

Log:
gc_alloc performance test
Added:
   sandbox/memory/libs/memory/test/test_basic/memory/exception_semantics.cpp (contents, props changed)
Text files modified:
   sandbox/memory/boost/memory/gc_alloc.hpp | 4
   sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp | 81 ++++++++++++++++++++++++++++++++++-----
   sandbox/memory/libs/memory/test/test_basic/test.cpp | 5 +
   sandbox/memory/libs/memory/test/test_basic/test.dsp | 4 +
   4 files changed, 79 insertions(+), 15 deletions(-)

Modified: sandbox/memory/boost/memory/gc_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/gc_alloc.hpp (original)
+++ sandbox/memory/boost/memory/gc_alloc.hpp 2008-05-07 01:22:09 EDT (Wed, 07 May 2008)
@@ -31,7 +31,7 @@
 // -------------------------------------------------------------------------
 // class gen_alloc
 
-#ifdef _DEBUG
+#if defined(_DEBUG) && !defined(BOOST_MEMORY_TRACE_GC)
 #define BOOST_MEMORY_TRACE_GC
 #endif
 
@@ -267,7 +267,7 @@
                                                 it->cbNodeSize += it2->cbNodeSize;
                                         }
                                         if (it->cbNodeSize >= RecycleSizeMin)
- m_freeList.push((FreeMemHeader*)it);
+ m_freeList.push(it);
                                         if (coll.done())
                                                 break;
                                 }

Added: sandbox/memory/libs/memory/test/test_basic/memory/exception_semantics.cpp
==============================================================================
--- (empty file)
+++ sandbox/memory/libs/memory/test/test_basic/memory/exception_semantics.cpp 2008-05-07 01:22:09 EDT (Wed, 07 May 2008)
@@ -0,0 +1,65 @@
+//
+// exception_semantics.cpp
+//
+// Copyright (c) 2004 - 2008 xushiwei (xushiweizh_at_[hidden])
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/memory/index.htm for documentation.
+//
+#include <cstdio>
+
+class A
+{
+public:
+ A() {}
+ void init() {
+ printf("A::A\n");
+ }
+ ~A() {
+ printf("A::~A\n");
+ }
+};
+
+class B
+{
+public:
+ B() {}
+ void init() {
+ printf("B::B\n");
+ }
+ ~B() {
+ printf("B::~B\n");
+ }
+};
+
+class Foo
+{
+private:
+ A m_a;
+ B m_b;
+
+public:
+ Foo() {
+ m_a.init();
+ throw 1;
+ m_b.init();
+ }
+ ~Foo() {
+ printf("Foo::~Foo\n");
+ }
+};
+
+void testExceptionSemantics()
+{
+ try
+ {
+ Foo a;
+ }
+ catch (...)
+ {
+ printf("Unexcepted\n");
+ }
+}

Modified: sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp (original)
+++ sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp 2008-05-07 01:22:09 EDT (Wed, 07 May 2008)
@@ -25,14 +25,23 @@
 class TestAllocatorPerformance
 {
 private:
+ enum { Total = 1000000 };
+
         NS_BOOST_DETAIL::accumulator m_acc;
         NS_BOOST_MEMORY::block_pool m_recycle;
+ int** p;
 
 public:
+ TestAllocatorPerformance() {
+ p = new int*[Total];
+ }
+ ~TestAllocatorPerformance() {
+ delete[] p;
+ }
+
         void doNewDelete(LogT& log, int NAlloc, int PerAlloc)
         {
- int i, **p;
- p = new int*[PerAlloc];
+ int i;
                 NS_BOOST_DETAIL::performance_counter counter;
                 {
                         for (int j = 0; j < NAlloc; ++j)
@@ -48,7 +57,6 @@
                         }
                 }
                 m_acc.accumulate(counter.trace(log));
- delete[] p;
         }
 
 #if defined(__GNUG__)
@@ -164,7 +172,45 @@
                 m_acc.accumulate(counter.trace(log));
         }
 
- void doComparison(LogT& log, int Total, int NAlloc)
+ template <class LogT2>
+ void doGcAlloc(LogT2& log, int NAlloc, int PerAlloc)
+ {
+ NS_BOOST_DETAIL::performance_counter counter;
+ {
+ for (int j = 0; j < NAlloc; ++j)
+ {
+ boost::gc_alloc alloc(m_recycle);
+ for (int i = 0; i < PerAlloc; ++i)
+ {
+ int* p = BOOST_NEW(alloc, int);
+ }
+ }
+ }
+ m_acc.accumulate(counter.trace(log));
+ }
+
+ void doGcAllocManually(LogT& log, int NAlloc, int PerAlloc)
+ {
+ int i;
+ NS_BOOST_DETAIL::performance_counter counter;
+ {
+ for (int j = 0; j < NAlloc; ++j)
+ {
+ boost::gc_alloc alloc(m_recycle);
+ for (i = 0; i < PerAlloc/2; ++i)
+ p[i] = BOOST_NEW(alloc, int);
+ for (i = 0; i < PerAlloc/2; ++i)
+ alloc.destroy(p[i]);
+ for (i = 0; i < PerAlloc/2; ++i)
+ p[i] = BOOST_NEW(alloc, int);
+ for (i = 0; i < PerAlloc/2; ++i)
+ alloc.destroy(p[i]);
+ }
+ }
+ m_acc.accumulate(counter.trace(log));
+ }
+
+ void doComparison(LogT& log, int NAlloc)
         {
                 int i;
                 const int Count = 16;
@@ -188,6 +234,18 @@
                         doScopedAlloc(log, NAlloc, PerAlloc);
                 m_acc.trace_avg(log);
 
+ m_acc.start();
+ log.trace("\n===== boost::gc_alloc(%d) =====\n", PerAlloc);
+ for (i = 0; i < Count; ++i)
+ doGcAlloc(log, NAlloc, PerAlloc);
+ m_acc.trace_avg(log);
+
+ m_acc.start();
+ log.trace("\n===== boost::gc_alloc manually(%d) =====\n", PerAlloc);
+ for (i = 0; i < Count; ++i)
+ doGcAllocManually(log, NAlloc, PerAlloc);
+ m_acc.trace_avg(log);
+
 #if defined(__GNUG__)
                 m_acc.start();
                 log.trace("\n===== MtAllocator(%d) =====\n", PerAlloc);
@@ -219,14 +277,13 @@
         {
                 NS_BOOST_DETAIL::null_log nullLog;
                 
- const int Total = 1000000;
- doAutoAlloc(nullLog, Total, 1);
- doTlsScopedAlloc(nullLog, Total, 1);
- doScopedAlloc(nullLog, Total, 1);
-
- doComparison(log, Total, Total);
- doComparison(log, Total, 1000);
- doComparison(log, Total, 1);
+ doAutoAlloc(nullLog, 1, Total);
+ doTlsScopedAlloc(nullLog, 1, Total);
+ doScopedAlloc(nullLog, 1, Total);
+
+ doComparison(log, Total);
+ doComparison(log, 1000);
+ doComparison(log, 1);
         }
 };
 

Modified: sandbox/memory/libs/memory/test/test_basic/test.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/test_basic/test.cpp (original)
+++ sandbox/memory/libs/memory/test/test_basic/test.cpp 2008-05-07 01:22:09 EDT (Wed, 07 May 2008)
@@ -16,12 +16,15 @@
 void testPerformance();
 void testSystemAlloc();
 void testStlContainers();
+void testExceptionSemantics();
 void simpleExamples();
 
 int main()
 {
-// testSystemAlloc();
         testPerformance();
+// testExceptionSemantics();
+// testSystemAlloc();
+// testPerformance();
 // simpleExamples();
 // testStlContainers();
         return 0;

Modified: sandbox/memory/libs/memory/test/test_basic/test.dsp
==============================================================================
--- sandbox/memory/libs/memory/test/test_basic/test.dsp (original)
+++ sandbox/memory/libs/memory/test/test_basic/test.dsp 2008-05-07 01:22:09 EDT (Wed, 07 May 2008)
@@ -86,6 +86,10 @@
 # Name "test - Win32 Debug"
 # Begin Source File
 
+SOURCE=.\memory\exception_semantics.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\memory\performance.cpp
 # End Source File
 # Begin Source File


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk