Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53986 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-16 22:36:25


Author: cschladetsch
Date: 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
New Revision: 53986
URL: http://svn.boost.org/trac/boost/changeset/53986

Log:
added monotonic::static_storage

Added:
   sandbox/monotonic/boost/monotonic/static_storage.h (contents, props changed)
Text files modified:
   sandbox/monotonic/boost/monotonic/allocator.h | 3 +
   sandbox/monotonic/boost/monotonic/shared_storage.h | 2
   sandbox/monotonic/boost/monotonic/storage.h | 4 +-
   sandbox/monotonic/boost/monotonic/storage_base.h | 3 ++
   sandbox/monotonic/libs/monotonic/test/main.cpp | 31 ++++++++++++++++++++-
   sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 12 ++++++++
   sandbox/monotonic/libs/monotonic/test/test_map_list.cpp | 57 ++++++++++++++++++++++++++++++---------
   7 files changed, 93 insertions(+), 19 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/allocator.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator.h (original)
+++ sandbox/monotonic/boost/monotonic/allocator.h 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
@@ -7,6 +7,7 @@
 
 #include <boost/monotonic/storage_base.h>
 #include <boost/monotonic/storage.h>
+#include <boost/monotonic/static_storage.h>
 #include <boost/assert.hpp>
 #include <boost/type_traits/has_trivial_constructor.hpp>
 #include <boost/type_traits/has_trivial_destructor.hpp>
@@ -61,7 +62,7 @@
 
                 public:
                         allocator() throw()
- : storage(0)
+ : storage(&static_storage)
                         {
                         }
 

Modified: sandbox/monotonic/boost/monotonic/shared_storage.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/shared_storage.h (original)
+++ sandbox/monotonic/boost/monotonic/shared_storage.h 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
@@ -19,7 +19,7 @@
                         typedef storage<InlineSize, MinHeapSize, Al> Storage;
                 private:
                         Storage storage;
- mutex guard;
+ mutable mutex guard;
 
                 public:
                         shared_storage()

Added: sandbox/monotonic/boost/monotonic/static_storage.h
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/monotonic/static_storage.h 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
@@ -0,0 +1,50 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// 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)
+
+#pragma once
+
+#include <boost/monotonic/storage.h>
+//#include <boost/monotonic/shared_storage.h>
+
+namespace boost
+{
+ namespace monotonic
+ {
+ template <class Storage>
+ struct static_storage_base : storage_base
+ {
+ static Storage global;
+
+ void reset()
+ {
+ global.reset();
+ }
+ void *allocate(size_t num_bytes, size_t alignment)
+ {
+ return global.allocate(num_bytes, alignment);
+ }
+ size_t max_size() const
+ {
+ return global.max_size();
+ }
+ size_t used() const
+ {
+ return global.used();
+ }
+ size_t remaining() const
+ {
+ return global.remaining();
+ }
+ };
+
+ template <>
+ storage<> static_storage_base<storage<> >::global;
+
+ extern static_storage_base<storage<> > static_storage;
+ //extern static_storage_base<shared_storage<> > static_shared_storage;
+ }
+}
+
+//EOF

Modified: sandbox/monotonic/boost/monotonic/storage.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/storage.h (original)
+++ sandbox/monotonic/boost/monotonic/storage.h 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
@@ -22,7 +22,7 @@
                 /// once that is exhausted, later requests are serviced from the heap.
                 ///
                 /// all allocations remain valid at all times.
- template <size_t InlineSize = 8*1024, size_t MinHeapSize = InlineSize*1000, class Al = std::allocator<char> >
+ template <size_t InlineSize = 8*1024, size_t MinHeapIncrement = InlineSize*1000, class Al = std::allocator<char> >
                 struct storage : storage_base
                 {
                         typedef Al Allocator;
@@ -114,7 +114,7 @@
                                                 return ptr;
                                         }
                                 }
- size_t size = std::max(MinHeapSize, num_bytes*2);
+ size_t size = std::max(MinHeapIncrement, num_bytes*2);
                                 return AddLink(size).Allocate(num_bytes, alignment);
                         }
 

Modified: sandbox/monotonic/boost/monotonic/storage_base.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/storage_base.h (original)
+++ sandbox/monotonic/boost/monotonic/storage_base.h 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
@@ -23,6 +23,9 @@
                         
                         virtual size_t max_size() const = 0;
                         
+ /// return the number of bytes used
+ virtual size_t used() const = 0;
+
                         /// return the number of bytes remaining
                         virtual size_t remaining() const = 0;
                 };

Modified: sandbox/monotonic/libs/monotonic/test/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/main.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/main.cpp 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
@@ -9,6 +9,7 @@
 #include <boost/monotonic/list.h>
 #include <boost/monotonic/map.h>
 #include <boost/monotonic/set.h>
+#include <boost/monotonic/static_storage.h>
 
 #include <boost/iterator/counting_iterator.hpp>
 
@@ -283,8 +284,33 @@
 #include "test_chained_storage.cpp"
 #include "test_shared_storage.cpp"
 
+namespace boost { namespace monotonic {
+static_storage_base<storage<> > static_storage;
+}}
+
+void test_static_storage()
+{
+ // reset the global static storage to zero use
+ monotonic::static_storage.reset();
+
+ typedef std::list<int, monotonic::allocator<int> > List;
+ typedef std::map<int, List, std::less<int>, monotonic::allocator<int> > Map;
+ {
+ List list0, list1;
+ Map map;
+ list0.push_back(1);
+ list1.push_back(2);
+ list0.splice(list0.begin(), list1);
+ map[42] = list0;
+ map[123] = list1;
+ }
+ cout << monotonic::static_storage.used() << endl;
+ monotonic::static_storage.reset();
+}
+
 void run_all_tests()
 {
+ test_static_storage();
         test_shared_storage();
         test_chained_storage();
         test_map_list_heap_stack();
@@ -300,8 +326,9 @@
 
 int main()
 {
- //test_map_list_heap_stack();
- run_all_tests();
+ test_map_list_heap_stack();
+ //test_static_storage();
+ //run_all_tests();
 }
 
 //EOF

Modified: sandbox/monotonic/libs/monotonic/test/monotonic.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.vcproj 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
@@ -210,6 +210,10 @@
>
                                 </File>
                                 <File
+ RelativePath="..\..\..\boost\monotonic\static_storage.h"
+ >
+ </File>
+ <File
                                         RelativePath="..\..\..\boost\monotonic\storage.h"
>
                                 </File>
@@ -255,6 +259,14 @@
                         RelativePath=".\basic_tests.cpp"
>
                         <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
                                 Name="Release|Win32"
                                 ExcludedFromBuild="true"
>

Modified: sandbox/monotonic/libs/monotonic/test/test_map_list.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/test_map_list.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/test_map_list.cpp 2009-06-16 22:36:24 EDT (Tue, 16 Jun 2009)
@@ -19,8 +19,20 @@
         }
 }
 
-pair<double,double> test_map_list(size_t outter_loops, size_t inner_loops, monotonic::storage_base &storage)
+struct Result
 {
+ double mono;
+ double standard;
+ double static_monotonic;
+ Result() : mono(0), standard(0), static_monotonic(0) { }
+ Result(double a, double b, double c) : mono(a), standard(b), static_monotonic(c) { }
+};
+
+Result test_map_list(size_t outter_loops, size_t inner_loops, monotonic::storage_base &storage)
+{
+ Result result;
+
+ // local monotonic allocator
         boost::timer t0;
         for (size_t n = 0; n < outter_loops; ++n)
         {
@@ -33,17 +45,34 @@
         }
         double e0 = t0.elapsed();
 
+ // standard allocator
         boost::timer t1;
         for (size_t n = 0; n < outter_loops; ++n)
         {
- typedef std::map<int, std::list<int> > Map;
- Map map;
- test_map_list_impl(inner_loops, map);
+ {
+ typedef std::map<int, std::list<int> > Map;
+ Map map;
+ test_map_list_impl(inner_loops, map);
+ }
         }
         double e1 = t1.elapsed();
 
- cout << "test_map_list: " << inner_loops << ": " << e0 << ", " << e1 << endl;
- return make_pair(e0, e1);
+ // static monotonic allocator
+ boost::timer t2;
+ monotonic::static_storage.reset();
+ for (size_t n = 0; n < outter_loops; ++n)
+ {
+ {
+ typedef std::map<int, std::list<int, monotonic::allocator<int> >, std::less<int>, monotonic::allocator<int> > Map;
+ Map map;
+ test_map_list_impl(inner_loops, map);
+ }
+ monotonic::static_storage.reset();
+ }
+ double e2 = t2.elapsed();
+
+ cout << "test_map_list: " << inner_loops << ": " << e0 << ", " << e1 << ", " << e2 << endl;
+ return Result(e0, e1, e2);
 }
 
 void test_map_list_heap_stack()
@@ -52,7 +81,7 @@
         const size_t inner_loops = 10000;
 
         monotonic::storage<> storage;
- typedef std::map<size_t, pair<double, double> > Results;
+ typedef std::map<size_t, Result > Results;
         Results results;
 
         for (size_t inner = 100; inner < inner_loops; inner += 1000)
@@ -61,14 +90,16 @@
         }
 
         cout << "test_map_list" << endl;
- BOOST_FOREACH(Results::value_type const &result, results)
+ BOOST_FOREACH(Results::value_type const &iter, results)
         {
- double mono_time = result.second.first;
- double std_time = result.second.second;
- double perc = mono_time/std_time;
- cout << result.first << '\t' << mono_time << '\t' << std_time << '\t' << perc << "%" << endl;
+ Result const &result = iter.second;
+ double mono_time = result.mono;
+ double std_time = result.standard;
+ double static_time = result.static_monotonic;
+ double perc1 = mono_time/std_time;
+ double perc2 = static_time/std_time;
+ cout << iter.first << '\t' << mono_time << '\t' << static_time << '\t' << std_time << '\t' << perc1 << "%\t" << perc2 << "%"<< endl;
         }
-
 }
 
 //EOF


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