|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54265 - in sandbox/monotonic: boost/monotonic boost/monotonic/extra libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-23 02:29:08
Author: cschladetsch
Date: 2009-06-23 02:29:07 EDT (Tue, 23 Jun 2009)
New Revision: 54265
URL: http://svn.boost.org/trac/boost/changeset/54265
Log:
added string tests
Text files modified:
sandbox/monotonic/boost/monotonic/extra/string.hpp | 4 +
sandbox/monotonic/boost/monotonic/local.hpp | 13 +++
sandbox/monotonic/libs/monotonic/test/Tests.h | 31 ++++++++
sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp | 138 ++++++++++++++++++++++++++++-----------
4 files changed, 146 insertions(+), 40 deletions(-)
Modified: sandbox/monotonic/boost/monotonic/extra/string.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/extra/string.hpp (original)
+++ sandbox/monotonic/boost/monotonic/extra/string.hpp 2009-06-23 02:29:07 EDT (Tue, 23 Jun 2009)
@@ -63,6 +63,10 @@
impl = other.impl;
return *this;
}
+ //string &operator+=(string const &other)
+ //{
+
+ //}
};
} // namespace monotonic
Modified: sandbox/monotonic/boost/monotonic/local.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/local.hpp (original)
+++ sandbox/monotonic/boost/monotonic/local.hpp 2009-06-23 02:29:07 EDT (Tue, 23 Jun 2009)
@@ -67,6 +67,19 @@
get_storage().destroy(X);
}
+ static size_t fixed_used()
+ {
+ return get_storage().fixed_used();
+ }
+ static size_t heap_used()
+ {
+ return get_storage().heap_used();
+ }
+ static size_t used()
+ {
+ return get_storage().used();
+ }
+
};
} // namespace monotonic
Modified: sandbox/monotonic/libs/monotonic/test/Tests.h
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/Tests.h (original)
+++ sandbox/monotonic/libs/monotonic/test/Tests.h 2009-06-23 02:29:07 EDT (Tue, 23 Jun 2009)
@@ -181,6 +181,37 @@
}
};
+struct test_string_cat
+{
+ template <class Alloc>
+ int test(Alloc alloc, size_t length) const
+ {
+ typedef std::basic_string<char, std::char_traits<char>, typename Rebind<Alloc, char>::type> String;
+ String str = "foo";
+ for (size_t n = 0; n < length; ++n)
+ {
+ str += "bar";
+ }
+ return 0;
+ }
+};
+
+struct test_list_string
+{
+ template <class Alloc>
+ int test(Alloc alloc, size_t length) const
+ {
+ typedef std::basic_string<char, std::char_traits<char>, typename Rebind<Alloc, char>::type> String;
+ typedef std::list<String, typename Rebind<Alloc, String>::type> List;
+ List list;
+ for (size_t n = 0; n < length; ++n)
+ {
+ list.push_back(String("spam"));
+ }
+ return 0;
+ }
+};
+
//Build a std::map of size n. Loop for O(n^2) iterations.
//In each iteration insert one random element and lookup with lower_bound one random element and remove it.
//Precompute the random numbers and don't include the rand() calls in the time measurement of the benchmark.
Modified: sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp 2009-06-23 02:29:07 EDT (Tue, 23 Jun 2009)
@@ -23,6 +23,8 @@
#include "./PoolResult.h"
#include "./Tests.h"
+#include <boost/monotonic/extra/string.hpp>
+
using namespace std;
using namespace boost;
@@ -141,13 +143,13 @@
}
template <class Fun>
-PoolResults run_tests(size_t count, size_t max_length, size_t num_iterations, const char *title, Fun fun, Type types = Type::All)
+PoolResults run_tests(size_t count, size_t max_length, size_t num_iterations, const char *title, Fun fun, Type types = Type::TBB | Type::Standard | Type::Monotonic)
{
boost::timer timer;
cout << title << ": reps=" << count << ", len=" << max_length << ", steps=" << num_iterations;
PoolResults results;
srand(42);
- for (size_t length = 1; length < max_length; length += max_length/num_iterations)
+ for (size_t length = 10; length < max_length; length += max_length/num_iterations)
{
size_t required = length + length*length;
if (random_numbers.size() < required)
@@ -268,33 +270,6 @@
#pragma warning(disable:4996)
#endif
-struct local_1 {};
-
-template <class Storage>
-void test_locals(Storage &storage)
-{
- typedef typename Storage::allocator<int>::type allocator;
-
- std::list<int, allocator > list;
- monotonic::storage_base *b0 = list.get_allocator().get_storage();
- monotonic::storage_base *b1 = &storage.get_storage();
-
- BOOST_ASSERT(list.get_allocator().get_storage() == &storage.get_storage());
- list.push_back(42);
- string &s = storage.create<string>("foo");
- std::vector<int, allocator > vec;
- BOOST_ASSERT(vec.get_allocator().get_storage() == &storage.get_storage());
- vec.resize(100);
- cout << "test_locals: stack,heap =" << storage.get_storage().fixed_used() << ", " << storage.get_storage().heap_used() << endl;
- storage.destroy(s);
-}
-
-void test_locals()
-{
- monotonic::local<local_1> storage;
- for (size_t n = 0; n < 10; ++n)
- test_locals(storage);
-}
void test_pools()
{
@@ -361,6 +336,85 @@
}
}
+template <class Storage>
+void test_locals(Storage &storage, size_t count)
+{
+ if (count == 0)
+ return;
+ typedef typename Storage::allocator<int>::type allocator;
+ typedef typename Storage::allocator<char>::type char_allocator;
+ std::list<int, allocator > list;
+ fill_n(back_inserter(list), 100, 42);
+ typedef std::basic_string<char, std::char_traits<char>, char_allocator> String;
+ String &s = storage.create<String>("foo");
+ for (size_t n = 0; n < 100; ++n)
+ s += "bar";
+ std::vector<int, allocator > vec;
+ vec.resize(1000);
+ storage.destroy(s);
+ test_locals(storage, --count);
+}
+
+struct local_1 {};
+struct local_2 {};
+
+void test_locals_mono()
+{
+ monotonic::local<local_1> storage1;
+ //monotonic::local<local_2> storage2;
+ for (size_t n = 0; n < 10; ++n)
+ {
+ test_locals(storage1, 4);
+ //test_locals(storage2, 2);
+ }
+ //cout << "test_locals: storage1 stack,heap =" << storage1.fixed_used() << ", " << storage1.heap_used() << endl;
+ //cout << "test_locals: storage2 stack,heap =" << storage2.fixed_used() << ", " << storage2.heap_used() << endl;
+}
+
+
+void test_locals_std_impl(size_t count)
+{
+ if (count == 0)
+ return;
+ std::list<int> list;
+ fill_n(back_inserter(list), 100, 42);
+ string s = "foo";
+ for (size_t n = 0; n < 100; ++n)
+ s += "bar";
+ std::vector<int> vec;
+ vec.resize(1000);
+ test_locals_std_impl(--count);
+}
+
+void test_locals_std()
+{
+ for (size_t n = 0; n < 10; ++n)
+ {
+ test_locals_std_impl(4);
+ }
+}
+
+void test_locals(size_t count)
+{
+ boost::timer t0;
+ for (size_t n = 0; n < count; ++n)
+ {
+ test_locals_mono();
+ }
+ double mono_elapsed = t0.elapsed();
+
+ boost::timer t1;
+ for (size_t n = 0; n < count; ++n)
+ {
+ test_locals_std();
+ }
+ double std_elapsed = t1.elapsed();
+
+ cout << "mono: " << mono_elapsed << endl;
+ cout << "std : " << std_elapsed << endl;
+}
+
+
int main()
{
try
@@ -368,7 +422,7 @@
cout << "results of running test at:" << endl;
cout << "https://svn.boost.org/svn/boost/sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp" << endl << endl;
- test_locals();
+ //test_locals(10000);
//test_pools();
//return 0;
@@ -392,25 +446,29 @@
{
heading("SMALL");
#ifndef WIN32
+ print(run_tests(100000, 100, 10, "string_cat", test_string_cat()));
+ print(run_tests(100000, 100, 10, "list_string", test_list_string()));
print(run_tests(75000, 100, 10, "list_create<int>", test_list_create<int>()));
print(run_tests(75000, 100, 10, "list_sort<int>", test_list_sort<int>()));
print(run_tests(2000000, 100, 10, "vector_create<int>", test_vector_create()));
print(run_tests(200000, 100, 10, "vector_sort<int>", test_vector_sort<int>()));
print(run_tests(1000000, 100, 10, "vector_dupe", test_vector_dupe()));
- print(run_tests(50000, 100, 10, "list_dupe", test_list_dupe(), test_dupe_list_types));
+ print(run_tests(50000, 100, 10, "list_dupe", test_list_dupe()));
print(run_tests(500000, 100, 10, "vector_accumulate", test_vector_accumulate()));
print(run_tests(10000, 100, 10, "set_vector", test_set_vector()));
- print(run_tests(2000, 100, 10, "map_vector<int>", test_map_vector<int>(), test_map_vector_types));
+ print(run_tests(2000, 100, 10, "map_vector<int>", test_map_vector<int>()));
#else
+ print(run_tests(50000, 100, 10, "string_cat", test_string_cat()));
+ print(run_tests(50000, 100, 10, "list_string", test_list_string()));
print(run_tests(50000, 100, 10, "list_create<int>", test_list_create<int>()));
print(run_tests(5000, 100, 10, "list_sort<int>", test_list_sort<int>()));
print(run_tests(2000000, 100, 10, "vector_create<int>", test_vector_create()));
print(run_tests(20000, 100, 10, "vector_sort<int>", test_vector_sort<int>()));
print(run_tests(100000, 100, 10, "vector_dupe", test_vector_dupe()));
- print(run_tests(20000, 100, 10, "list_dupe", test_list_dupe(), test_dupe_list_types));
+ print(run_tests(20000, 100, 10, "list_dupe", test_list_dupe()));
print(run_tests(500000, 100, 10, "vector_accumulate", test_vector_accumulate()));
print(run_tests(50, 100, 10, "set_vector", test_set_vector()));
- print(run_tests(500, 100, 10, "map_vector<int>", test_map_vector<int>(), test_map_vector_types));
+ print(run_tests(500, 100, 10, "map_vector<int>", test_map_vector<int>()));
#endif
heading("SUMMARY", '*');
@@ -428,10 +486,10 @@
print(run_tests(1000000, 100000, 10, "vector_create<int>", test_vector_create()));
print(run_tests(300, 10000, 10, "vector_sort<int>", test_vector_sort<int>()));
print(run_tests(1000000, 10000, 10, "vector_dupe", test_vector_dupe()));
- print(run_tests(2000, 1000, 10, "list_dupe", test_list_dupe(), test_dupe_list_types));
+ print(run_tests(2000, 1000, 10, "list_dupe", test_list_dupe()));
print(run_tests(5000000, 2000, 10, "vector_accumulate", test_vector_accumulate()));
print(run_tests(500, 1000, 10, "set_vector", test_set_vector()));
- print(run_tests(500, 1000, 10, "map_vector<int>", test_map_vector<int>(), test_map_vector_types));
+ print(run_tests(500, 1000, 10, "map_vector<int>", test_map_vector<int>()));
#else
print(run_tests(1000, 100000, 10, "vector_create<int>", test_vector_create()));
print(run_tests(30000, 1000, 10, "vector_sort<int>", test_vector_sort<int>()));
@@ -439,7 +497,7 @@
print(run_tests(500, 1000, 10, "list_dupe", test_list_dupe(), test_dupe_list_types));
print(run_tests(50000, 2000, 10, "vector_accumulate", test_vector_accumulate()));
print(run_tests(20, 500, 5, "set_vector", test_set_vector()));
- print(run_tests(50, 1000, 10, "map_vector<int>", test_map_vector<int>(), test_map_vector_types));
+ print(run_tests(50, 1000, 10, "map_vector<int>", test_map_vector<int>()));
#endif
heading("SUMMARY", '*');
print_cumulative(cumulative);
@@ -456,10 +514,10 @@
print(run_tests(100, 500000, 10, "vector_sort<int>", test_vector_sort<int>()));
print(run_tests(1000000, 100000000, 10, "vector_dupe", test_vector_dupe()));
- print(run_tests(100, 10000, 10, "list_dupe", test_list_dupe(), test_dupe_list_types));
+ print(run_tests(100, 10000, 10, "list_dupe", test_list_dupe()));
print(run_tests(1000000, 20000000, 10, "vector_accumulate", test_vector_accumulate()));
print(run_tests(10, 50000, 10, "set_vector", test_set_vector()));
- print(run_tests(10, 10000, 10, "map_vector<int>", test_map_vector<int>(), test_map_vector_types));
+ print(run_tests(10, 10000, 10, "map_vector<int>", test_map_vector<int>()));
#else
print(run_tests(10, 25000, 10, "list_create<int>", test_list_create<int>()));
print(run_tests(10, 100000, 10, "list_sort<int>", test_list_sort<int>()));
@@ -469,7 +527,7 @@
print(run_tests(50, 10000, 10, "list_dupe", test_list_dupe(), test_dupe_list_types));
print(run_tests(500, 10000000, 10, "vector_accumulate", test_vector_accumulate()));
print(run_tests(5, 2000, 5, "set_vector", test_set_vector()));
- print(run_tests(10, 2000, 10, "map_vector<int>", test_map_vector<int>(), test_map_vector_types));
+ print(run_tests(10, 2000, 10, "map_vector<int>", test_map_vector<int>()));
#endif
}
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