$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r53922 - sandbox/monotonic/libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-15 03:24:49
Author: cschladetsch
Date: 2009-06-15 03:24:49 EDT (Mon, 15 Jun 2009)
New Revision: 53922
URL: http://svn.boost.org/trac/boost/changeset/53922
Log:
added graph for bubble sort results
Added:
   sandbox/monotonic/libs/monotonic/test/test_bubble_sort.cpp   (contents, props changed)
Added: sandbox/monotonic/libs/monotonic/test/test_bubble_sort.cpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/libs/monotonic/test/test_bubble_sort.cpp	2009-06-15 03:24:49 EDT (Mon, 15 Jun 2009)
@@ -0,0 +1,74 @@
+template <class List>
+void test_bubble_sort_impl(size_t length, List &list)
+{
+	for (size_t n = 0; n < length; ++n)
+		list.push_back(length - n);
+	bool swapped = false;
+	do
+	{
+		swapped = false;
+		typename List::iterator A = list.begin(), B = --list.end();
+		for (--B; A != B; ++A)
+		{
+			typename List::iterator C = A;
+			++C;
+			if (*A > *C)
+			{
+				std::swap(*A, *C);
+				swapped = true;
+			}
+		}
+	}
+	while (swapped);
+}
+
+pair<double,double> test_bubble_sort(size_t count = 50*1000, size_t length = 20)
+{
+	monotonic::inline_storage<100000> storage;
+	boost::timer mono_timer;
+	for (size_t n = 0; n < count; ++n)
+	{
+		std::list<int, monotonic::allocator<int> > list(storage);
+		test_bubble_sort_impl(length, list);
+		storage.reset();
+	}
+	double mono_total = mono_timer.elapsed();
+
+	boost::timer std_timer;
+	for (size_t n = 0; n < count; ++n)
+	{
+		std::list<int> list;
+		test_bubble_sort_impl(length, list);
+	}
+	double std_total = std_timer.elapsed();
+	return make_pair(mono_total, std_total);
+}
+
+void graph_bubble_sort()
+{
+	const size_t count = 10000;
+	typedef std::map<size_t, pair<double, double> > Results;
+	Results results;
+	for (size_t length = 3; length < 50; length += 10)
+	{
+		results[length] = test_bubble_sort(count, length);
+	}
+	stringstream chart;
+	chart << "http://chart.apis.google.com/chart?chco=FF0000,00FF00&chs=250x100&cht=lc&chd=t:";
+	stringstream first;
+	stringstream second;
+	string comma = "";
+	double m = 0;
+	BOOST_FOREACH(Results::value_type const &result, results)
+	{
+		cout << result.first << '\t' << result.second.first << '\t' << result.second.second << endl;
+		first << comma << result.second.first;
+		second << comma << result.second.second;
+		comma = ",";
+		m = max(m, max(result.second.first, result.second.second));
+	}
+	chart << first.str() << "|" << second.str() << "&chds=0," << m << ",0," << m;
+	cout << chart.str() << endl;
+}
+
+//EOF