Boost logo

Boost-Commit :

From: xushiweizh_at_[hidden]
Date: 2008-05-06 10:38:45


Author: xushiwei
Date: 2008-05-06 10:38:45 EDT (Tue, 06 May 2008)
New Revision: 45173
URL: http://svn.boost.org/trac/boost/changeset/45173

Log:
system_alloc performance
Added:
   sandbox/memory/libs/memory/test/test_basic/memory/system_alloc_perform.cpp (contents, props changed)
Text files modified:
   sandbox/memory/libs/memory/test/test_basic/test.cpp | 4 +++-
   sandbox/memory/libs/memory/test/test_basic/test.dsp | 4 ++++
   2 files changed, 7 insertions(+), 1 deletions(-)

Added: sandbox/memory/libs/memory/test/test_basic/memory/system_alloc_perform.cpp
==============================================================================
--- (empty file)
+++ sandbox/memory/libs/memory/test/test_basic/memory/system_alloc_perform.cpp 2008-05-06 10:38:45 EDT (Tue, 06 May 2008)
@@ -0,0 +1,76 @@
+//
+// system_alloc_perform.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 <boost/memory.hpp>
+#include <boost/detail/performance_counter.hpp>
+
+template <class LogT>
+class TestSystemAlloc
+{
+private:
+ void** p;
+ enum { Total = 5000 };
+
+public:
+ TestSystemAlloc()
+ {
+ p = new void*[Total];
+ }
+ ~TestSystemAlloc()
+ {
+ delete[] p;
+ }
+
+ template <class LogT2, class AllocT>
+ void doTestAlloc(LogT2& log, AllocT& alloc)
+ {
+ NS_BOOST_DETAIL::accumulator acc;
+ for (int i, j = 0; j < 16; ++j)
+ {
+ NS_BOOST_DETAIL::performance_counter counter;
+ {
+ for (i = 0; i < Total; ++i)
+ {
+ p[i] = alloc.allocate(BOOST_MEMORY_BLOCK_SIZE);
+ }
+ for (i = 0; i < Total; ++i)
+ {
+ alloc.deallocate(p[i]);
+ }
+ }
+ acc.accumulate(counter.trace(log));
+ }
+ acc.trace_avg(log);
+ }
+
+ void test(LogT& log)
+ {
+ NS_BOOST_MEMORY::system_pool_dyn sysPool;
+ NS_BOOST_MEMORY::stdlib_alloc stdLib;
+
+ NS_BOOST_DETAIL::null_log nullLog;
+ doTestAlloc(nullLog, sysPool);
+
+ log.trace("\n===== StdLibAlloc =====\n");
+ doTestAlloc(log, stdLib);
+
+ log.trace("\n===== SystemPoolAlloc =====\n");
+ doTestAlloc(log, sysPool);
+ }
+};
+
+void testSystemAlloc()
+{
+ typedef NS_BOOST_DETAIL::stdout_log LogT;
+ LogT log;
+ TestSystemAlloc<LogT> test;
+ test.test(log);
+}

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-06 10:38:45 EDT (Tue, 06 May 2008)
@@ -14,12 +14,14 @@
 #include <boost/memory/linklib.hpp>
 
 void testPerformance();
+void testSystemAlloc();
 void testStlContainers();
 void simpleExamples();
 
 int main()
 {
- testPerformance();
+ 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-06 10:38:45 EDT (Tue, 06 May 2008)
@@ -98,6 +98,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\memory\system_alloc_perform.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\test.cpp
 # End Source File
 # End Target


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