Boost logo

Boost-Commit :

From: ramey_at_[hidden]
Date: 2008-06-10 00:28:37


Author: ramey
Date: 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
New Revision: 46286
URL: http://svn.boost.org/trac/boost/changeset/46286

Log:
New section for library performance testing and profiling
Added:
   trunk/libs/serialization/performance/
   trunk/libs/serialization/performance/Jamfile.v2 (contents, props changed)
   trunk/libs/serialization/performance/binary_archive.hpp (contents, props changed)
   trunk/libs/serialization/performance/binary_warchive.hpp (contents, props changed)
   trunk/libs/serialization/performance/peformance_array.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_binary.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_codecvt_null.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_iterators.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_iterators_base64.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_no_rtti.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_polymorphic.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_simple_class.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_utf8_codecvt.cpp (contents, props changed)
   trunk/libs/serialization/performance/performance_vector.cpp (contents, props changed)
   trunk/libs/serialization/performance/polymorphic_array_binary_archive.hpp (contents, props changed)
   trunk/libs/serialization/performance/polymorphic_binary_archive.hpp (contents, props changed)
   trunk/libs/serialization/performance/polymorphic_text_archive.hpp (contents, props changed)
   trunk/libs/serialization/performance/polymorphic_text_warchive.hpp (contents, props changed)
   trunk/libs/serialization/performance/polymorphic_xml_archive.hpp (contents, props changed)
   trunk/libs/serialization/performance/polymorphic_xml_warchive.hpp (contents, props changed)
   trunk/libs/serialization/performance/portable_binary_archive.hpp (contents, props changed)
   trunk/libs/serialization/performance/profile.sh (contents, props changed)
   trunk/libs/serialization/performance/text_archive.hpp (contents, props changed)
   trunk/libs/serialization/performance/text_warchive.hpp (contents, props changed)
   trunk/libs/serialization/performance/xml_archive.hpp (contents, props changed)
   trunk/libs/serialization/performance/xml_warchive.hpp (contents, props changed)

Added: trunk/libs/serialization/performance/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/Jamfile.v2 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,48 @@
+# Boost serialization Library performance test Jamfile
+
+# (C) Copyright Robert Ramey 2002-2004.
+# Use, modification, and distribution are subject to 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)
+#
+
+project libs/serialization/performance
+ : default-build release
+ : id serialization_performance
+ ;
+
+# import rules from the boost serialization test
+# import ../util/test : test-bsl-run-no-lib ;
+import ../util/test :
+ run-template
+ run-invoke
+ run-winvoke
+ test-bsl-run-no-lib
+ test-bsl-run
+ test-bsl-run_archive
+ test-bsl-run_files
+ test-bsl-run_polymorphic_archive
+;
+
+BOOST_ARCHIVE_LIST = [ modules.peek : BOOST_ARCHIVE_LIST ] ;
+
+test-suite "performance" :
+ [ test-bsl-run_files peformance_array : ../test/A ]
+# [ test-bsl-run_files performance_binary ]
+# [ test-bsl-run_files performance_polymorphic ]
+# [ test-bsl-run_files performance_vector ]
+# [ test-bsl-run_files performance_no_rtti ]
+# [ test-bsl-run_files performance_simple_class ]
+# [ test-bsl-run_polymorphic_archive performance_polymorphic : ../test/test_polymorphic_A ]
+
+ [ test-bsl-run-no-lib performance_iterators ]
+ [ test-bsl-run-no-lib performance_iterators_base64 ]
+# [ test-bsl-run-no-lib performance_utf8_codecvt
+# : ../src/utf8_codecvt_facet
+# : # <dependency>../../config/test/all//BOOST_NO_STD_WSTREAMBUF
+# ]
+# [ test-bsl-run-no-lib performance_codecvt_null
+# : ../src/codecvt_null
+# : # <dependency>../../config/test/all//BOOST_NO_STD_WSTREAMBUF
+# ]
+;

Added: trunk/libs/serialization/performance/binary_archive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/binary_archive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,22 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+
+// binary_archive
+#include <boost/archive/binary_oarchive.hpp>
+typedef boost::archive::binary_oarchive test_oarchive;
+typedef std::ofstream test_ostream;
+#include <boost/archive/binary_iarchive.hpp>
+typedef boost::archive::binary_iarchive test_iarchive;
+typedef std::ifstream test_istream;
+#define TEST_STREAM_FLAGS std::ios::binary
+

Added: trunk/libs/serialization/performance/binary_warchive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/binary_warchive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,14 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+// binary_warchive
+#include <boost/archive/binary_woarchive.hpp>
+typedef boost::archive::binary_woarchive test_oarchive;
+typedef std::wofstream test_ostream;
+#include <boost/archive/binary_wiarchive.hpp>
+typedef boost::archive::binary_wiarchive test_iarchive;
+typedef std::wifstream test_istream;
+#define TEST_STREAM_FLAGS std::wios::binary

Added: trunk/libs/serialization/performance/peformance_array.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/peformance_array.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,118 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_array.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+// should pass compilation and execution
+
+#include <fstream>
+#include <cstdio> // remove
+#include <boost/config.hpp>
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::remove;
+}
+#endif
+
+#include "../test/test_tools.hpp"
+
+#include <boost/preprocessor/stringize.hpp>
+//#include <boost/preprocessor/cat.hpp>
+// the following fails with (only!) gcc 3.4
+// #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
+// just copy over the files from the test directory
+#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
+
+#include <boost/detail/no_exceptions_support.hpp>
+#include <boost/archive/archive_exception.hpp>
+
+#include <boost/serialization/nvp.hpp>
+#include "../test/A.hpp"
+#include "../test/A.ipp"
+
+struct array_equal_to //: public std::binary_function<T, T, bool>
+{
+template<class T, class U>
+ bool operator()(const T & _Left, const U & _Right) const
+ {
+ // consider alignment
+ int count_left = sizeof(_Left) / (
+ static_cast<const char *>(static_cast<const void *>(&_Left[1]))
+ - static_cast<const char *>(static_cast<const void *>(&_Left[0]))
+ );
+ int count_right = sizeof(_Right) / (
+ static_cast<const char *>(static_cast<const void *>(&_Right[1]))
+ - static_cast<const char *>(static_cast<const void *>(&_Right[0]))
+ );
+ if(count_right != count_left)
+ return false;
+ while(count_left-- > 0){
+ if(_Left[count_left] == _Right[count_left])
+ continue;
+ return false;
+ }
+ return true;
+ }
+};
+
+template <class T>
+int test_array(T)
+{
+ const char * testfile = boost::archive::tmpnam(NULL);
+ BOOST_REQUIRE(NULL != testfile);
+
+ // test array of objects
+ const T a_array[10]={T(),T(),T(),T(),T(),T(),T(),T(),T(),T()};
+ {
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
+ oa << boost::serialization::make_nvp("a_array", a_array);
+ }
+ {
+ T a_array1[10];
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
+ ia >> boost::serialization::make_nvp("a_array", a_array1);
+
+ array_equal_to/*<A[10]>*/ Compare;
+ BOOST_CHECK(Compare(a_array, a_array1));
+ }
+ {
+ T a_array1[9];
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ BOOST_TRY {
+ test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
+ bool exception_invoked = false;
+ BOOST_TRY {
+ ia >> boost::serialization::make_nvp("a_array", a_array1);
+ }
+ BOOST_CATCH (boost::archive::archive_exception ae){
+ BOOST_CHECK(
+ boost::archive::archive_exception::array_size_too_short
+ == ae.code
+ );
+ exception_invoked = true;
+ }
+ BOOST_CATCH_END
+ BOOST_CHECK(exception_invoked);
+ }
+ BOOST_CATCH (boost::archive::archive_exception ae){}
+ BOOST_CATCH_END
+ }
+ std::remove(testfile);
+ return EXIT_SUCCESS;
+}
+
+int test_main( int /* argc */, char* /* argv */[] )
+{
+ int res = test_array(A());
+ // test an int array for which optimized versions should be available
+ if (res == EXIT_SUCCESS)
+ res = test_array(0);
+ return res;
+}
+
+// EOF

Added: trunk/libs/serialization/performance/performance_binary.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_binary.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,96 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_simple_class.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+// should pass compilation and execution
+
+#include <fstream>
+
+#include <cstdlib> // for rand()
+#include <cstdio> // remove
+#include <boost/config.hpp>
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::rand;
+ using ::remove;
+}
+#endif
+
+#include "../test/test_tools.hpp"
+#include <boost/preprocessor/stringize.hpp>
+// #include <boost/preprocessor/cat.hpp>
+// the following fails with (only!) gcc 3.4
+// #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
+// just copy over the files from the test directory
+#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
+
+#include <boost/serialization/nvp.hpp>
+#include <boost/serialization/binary_object.hpp>
+
+class A {
+ friend class boost::serialization::access;
+ char data[150];
+ // note: from an aesthetic perspective, I would much prefer to have this
+ // defined out of line. Unfortunately, this trips a bug in the VC 6.0
+ // compiler. So hold our nose and put it her to permit running of tests.
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /* file_version */){
+ ar & boost::serialization::make_nvp(
+ "data",
+ boost::serialization::make_binary_object(data, sizeof(data))
+ );
+ }
+
+public:
+ A();
+ bool operator==(const A & rhs) const;
+};
+
+A::A(){
+ int i = sizeof(data);
+ while(i-- > 0)
+ data[i] = 0xff & std::rand();
+}
+
+bool A::operator==(const A & rhs) const {
+ int i = sizeof(data);
+ while(i-- > 0)
+ if(data[i] != rhs.data[i])
+ return false;
+ return true;
+}
+
+int test_main( int /* argc */, char* /* argv */[] )
+{
+ const char * testfile = boost::archive::tmpnam(NULL);
+ BOOST_REQUIRE(NULL != testfile);
+
+ const A a;
+ A a1;
+ const int i = 12345;
+ int i1 = 34790;
+ {
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
+ oa << BOOST_SERIALIZATION_NVP(a);
+ // note: add a little bit on the end of the archive to detect
+ // failure of text mode binary.
+ oa << BOOST_SERIALIZATION_NVP(i);
+ }
+ {
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
+ ia >> BOOST_SERIALIZATION_NVP(a1);
+ ia >> BOOST_SERIALIZATION_NVP(i1);
+ }
+ BOOST_CHECK(i == i1);
+ BOOST_CHECK(a == a1);
+ std::remove(testfile);
+ return EXIT_SUCCESS;
+}
+
+// EOF

Added: trunk/libs/serialization/performance/performance_codecvt_null.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_codecvt_null.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,136 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_codecvt_null.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+// should pass compilation and execution. Note: compilation with compilers
+// which use wchar_t as 2 byte objects will emit warnings. These should be
+// ignored.
+
+#include <algorithm>
+#include <fstream>
+#include <iostream>
+#include <iterator>
+#include <locale>
+#include <vector>
+#include <cstddef>
+
+#include <cstdio> // remove
+#include <boost/config.hpp>
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::remove;
+}
+#endif
+
+#include "test_tools.hpp"
+
+#include <boost/archive/add_facet.hpp>
+#include <boost/archive/codecvt_null.hpp>
+#include <boost/archive/iterators/ostream_iterator.hpp>
+#include <boost/archive/iterators/istream_iterator.hpp>
+
+template<std::size_t S>
+struct test_data
+{
+ static wchar_t wchar_encoding[];
+};
+
+template<>
+wchar_t test_data<2>::wchar_encoding[] = {
+ 0x0001,
+ 0x007f,
+ 0x0080,
+ 0x07ff,
+ 0x0800,
+ 0x7fff
+};
+
+template<>
+wchar_t test_data<4>::wchar_encoding[] = {
+ 0x00000001,
+ 0x0000007f,
+ 0x00000080,
+ 0x000007ff,
+ 0x00000800,
+ 0x0000ffff,
+ 0x00010000,
+ 0x0010ffff,
+ 0x001fffff,
+ 0x00200000,
+ 0x03ffffff,
+ 0x04000000,
+ 0x7fffffff
+};
+
+#include <iostream>
+
+int test_main( int /* argc */, char* /* argv */[] ) {
+ const char * testfile = boost::archive::tmpnam(NULL);
+ BOOST_REQUIRE(NULL != testfile);
+
+ std::locale old_loc;
+ std::locale * null_locale =
+ boost::archive::add_facet(old_loc, new boost::archive::codecvt_null<wchar_t>);
+
+ typedef test_data<sizeof(wchar_t)> td;
+ {
+ std::wofstream ofs;
+ ofs.imbue(*null_locale);
+ ofs.open(testfile, std::ios::binary);
+ std::copy(
+ td::wchar_encoding,
+ #if ! defined(__BORLANDC__)
+ // borland 5.60 complains about this
+ td::wchar_encoding + sizeof(td::wchar_encoding)/sizeof(wchar_t),
+ #else
+ // so use this instead
+ td::wchar_encoding + 6,
+ #endif
+ boost::archive::iterators::ostream_iterator<wchar_t>(ofs)
+ );
+ }
+ bool ok = false;
+ {
+ std::wifstream ifs;
+ ifs.imbue(*null_locale);
+ ifs.open(testfile, std::ios::binary);
+ ok = std::equal(
+ td::wchar_encoding,
+ #if ! defined(__BORLANDC__)
+ // borland 5.60 complains about this
+ td::wchar_encoding + sizeof(td::wchar_encoding)/sizeof(wchar_t),
+ #else
+ // so use this instead
+ td::wchar_encoding + 6,
+ #endif
+ boost::archive::iterators::istream_iterator<wchar_t>(ifs)
+ );
+ }
+
+ BOOST_CHECK(ok);
+ {
+ std::wofstream ofs("testfile2");
+ ofs.imbue(*null_locale);
+ int i = 10;
+ ofs << i;
+ ofs.close();
+
+ std::wifstream ifs("testfile2");
+ ifs.imbue(*null_locale);
+ int i2;
+ ifs >> i2;
+ std::cout << "i=" << i << std::endl;
+ std::cout << "i2=" << i2 << std::endl;
+ BOOST_CHECK(i == i2);
+ ifs.close();
+ }
+
+ delete null_locale;
+ std::remove(testfile);
+ return EXIT_SUCCESS;
+}
+

Added: trunk/libs/serialization/performance/performance_iterators.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_iterators.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,213 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_iterators.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+#include <algorithm>
+#include <vector>
+#include <cstdlib> // for rand
+#include <functional>
+#include <sstream> // used to test stream iterators
+
+#include <boost/config.hpp>
+#ifdef BOOST_NO_STDC_NAMESPACE
+namespace std{
+ using ::rand;
+}
+#endif
+
+#include <boost/detail/workaround.hpp>
+#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
+#include <boost/archive/dinkumware.hpp>
+#endif
+
+#ifndef BOOST_NO_CWCHAR
+#include <boost/archive/iterators/mb_from_wchar.hpp>
+#include <boost/archive/iterators/wchar_from_mb.hpp>
+#endif
+#include <boost/archive/iterators/xml_escape.hpp>
+#include <boost/archive/iterators/xml_unescape.hpp>
+#include <boost/archive/iterators/transform_width.hpp>
+#include <boost/archive/iterators/istream_iterator.hpp>
+#include <boost/archive/iterators/ostream_iterator.hpp>
+
+#include "../test/test_tools.hpp"
+
+#ifndef BOOST_NO_CWCHAR
+
+void test_wchar_from_mb(const wchar_t *la, const char * a, const unsigned int size){
+ typedef boost::archive::iterators::wchar_from_mb<const char *> translator;
+ BOOST_CHECK((
+ std::equal(
+ translator(BOOST_MAKE_PFTO_WRAPPER(a)),
+ translator(BOOST_MAKE_PFTO_WRAPPER(a + size)),
+ la
+ )
+ ));
+}
+
+void test_mb_from_wchar(const char * a, const wchar_t *la, const unsigned int size){
+ typedef boost::archive::iterators::mb_from_wchar<const wchar_t *> translator;
+ BOOST_CHECK(
+ std::equal(
+ translator(BOOST_MAKE_PFTO_WRAPPER(la)),
+ translator(BOOST_MAKE_PFTO_WRAPPER(la + size)),
+ a
+ )
+ );
+}
+
+#endif
+
+template<class CharType>
+void test_xml_escape(
+ const CharType * xml_escaped,
+ const CharType * xml,
+ unsigned int size
+){
+ typedef boost::archive::iterators::xml_escape<const CharType *> translator;
+
+ BOOST_CHECK(
+ std::equal(
+ translator(BOOST_MAKE_PFTO_WRAPPER(xml)),
+ translator(BOOST_MAKE_PFTO_WRAPPER(xml + size)),
+ xml_escaped
+ )
+ );
+}
+
+template<class CharType>
+void test_xml_unescape(
+ const CharType * xml,
+ const CharType * xml_escaped,
+ unsigned int size
+){
+
+ // test xml_unescape
+ typedef boost::archive::iterators::xml_unescape<const CharType *> translator;
+
+ BOOST_CHECK(
+ std::equal(
+ translator(BOOST_MAKE_PFTO_WRAPPER(xml_escaped)),
+ translator(BOOST_MAKE_PFTO_WRAPPER(xml_escaped + size)),
+ xml
+ )
+ );
+}
+
+template<int BitsOut, int BitsIn>
+void test_transform_width(unsigned int size){
+ // test transform_width
+ char rawdata[8];
+
+ char * rptr;
+ for(rptr = rawdata + 6; rptr-- > rawdata;)
+ *rptr = std::rand();
+
+ // convert 8 to 6 bit characters
+ typedef boost::archive::iterators::transform_width<
+ char *, BitsOut, BitsIn
+ > translator1;
+
+ std::vector<char> v6;
+
+ std::copy(
+ translator1(BOOST_MAKE_PFTO_WRAPPER(static_cast<char *>(rawdata))),
+ translator1(BOOST_MAKE_PFTO_WRAPPER(rawdata + size)),
+ std::back_inserter(v6)
+ );
+
+ // check to see we got the expected # of characters out
+ if(0 == size)
+ BOOST_CHECK(v6.size() == 0);
+ else
+ BOOST_CHECK(v6.size() == (size * BitsIn - 1 ) / BitsOut + 1);
+
+ typedef boost::archive::iterators::transform_width<
+ std::vector<char>::iterator, BitsIn, BitsOut
+ > translator2;
+
+ BOOST_CHECK(
+ std::equal(
+ rawdata,
+ rawdata + size,
+ translator2(BOOST_MAKE_PFTO_WRAPPER(v6.begin()))
+ )
+ );
+
+}
+
+template<class CharType>
+void test_stream_iterators(
+ const CharType * test_data,
+ unsigned int size
+){
+ std::basic_stringstream<CharType> ss;
+ boost::archive::iterators::ostream_iterator<CharType> osi =
+ boost::archive::iterators::ostream_iterator<CharType>(ss);
+ std::copy(test_data, test_data + size, osi);
+
+ BOOST_CHECK(size == ss.str().size());
+
+ boost::archive::iterators::istream_iterator<CharType> isi =
+ boost::archive::iterators::istream_iterator<CharType>(ss);
+ BOOST_CHECK(std::equal(test_data, test_data + size,isi));
+}
+
+int
+test_main(int /* argc */, char* /* argv */ [] )
+{
+ const char xml[] = "<+>+&+\"+'";
+ const char xml_escaped[] = "&lt;+&gt;+&amp;+&quot;+&apos;";
+ test_xml_escape<const char>(
+ xml_escaped,
+ xml,
+ sizeof(xml) / sizeof(char) - 1
+ );
+ test_xml_unescape<const char>(
+ xml,
+ xml_escaped,
+ sizeof(xml_escaped) / sizeof(char) - 1
+ );
+
+ const char a[] = "abcdefghijklmnopqrstuvwxyz";
+
+ #ifndef BOOST_NO_CWCHAR
+ const wchar_t wxml[] = L"<+>+&+\"+'";
+ const wchar_t wxml_escaped[] = L"&lt;+&gt;+&amp;+&quot;+&apos;";
+ test_xml_escape<const wchar_t>(
+ wxml_escaped,
+ wxml,
+ sizeof(wxml) / sizeof(wchar_t) - 1
+ );
+ test_xml_unescape<const wchar_t>(
+ wxml,
+ wxml_escaped,
+ sizeof(wxml_escaped) / sizeof(wchar_t) - 1
+ );
+
+ const wchar_t la[] = L"abcdefghijklmnopqrstuvwxyz";
+
+ test_wchar_from_mb(la, a, sizeof(a) / sizeof(char) - 1);
+ test_mb_from_wchar(a, la, sizeof(la) / sizeof(wchar_t) - 1);
+
+ test_stream_iterators<wchar_t>(la, sizeof(la)/sizeof(wchar_t) - 1);
+ #endif
+
+ test_stream_iterators<char>(a, sizeof(a) - 1);
+
+ test_transform_width<6, 8>(0);
+ test_transform_width<6, 8>(1);
+ test_transform_width<6, 8>(2);
+ test_transform_width<6, 8>(3);
+ test_transform_width<6, 8>(4);
+ test_transform_width<6, 8>(5);
+ test_transform_width<6, 8>(6);
+ test_transform_width<6, 8>(7);
+ test_transform_width<6, 8>(8);
+
+ return EXIT_SUCCESS;
+}

Added: trunk/libs/serialization/performance/performance_iterators_base64.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_iterators_base64.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,100 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_iterators.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+#include <algorithm>
+#include <list>
+
+#if (defined _MSC_VER) && (_MSC_VER == 1200)
+# pragma warning (disable : 4786) // too long name, harmless warning
+#endif
+
+#include <cstdlib>
+#include <cstddef> // size_t
+
+#include <boost/config.hpp>
+#ifdef BOOST_NO_STDC_NAMESPACE
+namespace std{
+ using ::rand;
+ using ::size_t;
+}
+#endif
+
+#include <boost/pfto.hpp>
+
+#include <boost/archive/iterators/binary_from_base64.hpp>
+#include <boost/archive/iterators/base64_from_binary.hpp>
+#include <boost/archive/iterators/insert_linebreaks.hpp>
+#include <boost/archive/iterators/remove_whitespace.hpp>
+#include <boost/archive/iterators/transform_width.hpp>
+
+#include "../test/test_tools.hpp"
+
+#include <iostream>
+
+template<typename CharType>
+void test_base64(){
+ CharType rawdata[150];
+ std::size_t size = sizeof(rawdata) / sizeof(CharType);
+ CharType * rptr;
+ for(rptr = rawdata + size; rptr-- > rawdata;)
+ *rptr = std::rand();
+
+ // convert to base64
+ typedef std::list<CharType> text_base64_type;
+ text_base64_type text_base64;
+
+ typedef
+ boost::archive::iterators::insert_linebreaks<
+ boost::archive::iterators::base64_from_binary<
+ boost::archive::iterators::transform_width<
+ CharType *
+ ,6
+ ,sizeof(CharType) * 8
+ >
+ >
+ ,72
+ >
+ translate_out;
+
+ std::copy(
+ translate_out(BOOST_MAKE_PFTO_WRAPPER(static_cast<CharType *>(rawdata))),
+ translate_out(BOOST_MAKE_PFTO_WRAPPER(rawdata + size)),
+ std::back_inserter(text_base64)
+ );
+
+ // convert from base64 to binary and compare with the original
+ typedef
+ boost::archive::iterators::transform_width<
+ boost::archive::iterators::binary_from_base64<
+ boost::archive::iterators::remove_whitespace<
+ BOOST_DEDUCED_TYPENAME text_base64_type::iterator
+ >
+ >,
+ sizeof(CharType) * 8,
+ 6
+ > translate_in;
+
+ BOOST_CHECK(
+ std::equal(
+ rawdata,
+ rawdata + size,
+ translate_in(BOOST_MAKE_PFTO_WRAPPER(text_base64.begin()))
+ )
+ );
+
+}
+
+int
+test_main( int argc, char* argv[] )
+{
+ test_base64<char>();
+ #ifndef BOOST_NO_CWCHAR
+ test_base64<wchar_t>();
+ #endif
+ return EXIT_SUCCESS;
+}

Added: trunk/libs/serialization/performance/performance_no_rtti.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_no_rtti.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,222 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_no_rtti.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+// note: this program tests the inter-operability of different
+// extended typeinfo systems. In this example, one class is
+// identified using the default RTTI while the other uses a custom
+// system based on the export key.
+//
+// As this program uses RTTI for one of the types, the test will fail
+// on a system for which RTTI is not enabled or not existent.
+
+#include <fstream>
+
+#include <cstdio> // remove
+#include <boost/config.hpp>
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::remove;
+}
+#endif
+
+#include <boost/static_assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/archive/archive_exception.hpp>
+#include "../test/test_tools.hpp"
+#include <boost/preprocessor/stringize.hpp>
+// #include <boost/preprocessor/cat.hpp>
+// the following fails with (only!) gcc 3.4
+// #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
+// just copy over the files from the test directory
+#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
+
+#include <boost/serialization/nvp.hpp>
+#include <boost/serialization/base_object.hpp>
+#include <boost/serialization/export.hpp>
+#include <boost/serialization/type_info_implementation.hpp>
+#include <boost/serialization/extended_type_info_no_rtti.hpp>
+
+class polymorphic_base
+{
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & /* ar */, const unsigned int /* file_version */){
+ }
+public:
+ virtual const char * get_key() const = 0;
+ virtual ~polymorphic_base(){};
+};
+
+BOOST_IS_ABSTRACT(polymorphic_base)
+BOOST_CLASS_TYPE_INFO(
+ polymorphic_base,
+ extended_type_info_no_rtti<polymorphic_base>
+)
+// note: types which use ...no_rtti MUST be exported
+BOOST_CLASS_EXPORT(polymorphic_base)
+
+class polymorphic_derived1 : public polymorphic_base
+{
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive &ar, const unsigned int /* file_version */){
+ ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
+ }
+public:
+ virtual const char * get_key() const ;
+};
+
+BOOST_CLASS_TYPE_INFO(
+ polymorphic_derived1,
+ extended_type_info_no_rtti<polymorphic_derived1>
+)
+BOOST_CLASS_EXPORT(polymorphic_derived1)
+
+const char * polymorphic_derived1::get_key() const {
+ const boost::serialization::extended_type_info *eti
+ = boost::serialization::type_info_implementation<polymorphic_derived1>
+ ::type::get_instance();
+ return eti->get_key();
+}
+
+class polymorphic_derived2 : public polymorphic_base
+{
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive &ar, const unsigned int /* file_version */){
+ ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
+ }
+public:
+ virtual const char * get_key() const ;
+};
+
+// note the mixing of type_info systems is supported.
+BOOST_CLASS_TYPE_INFO(
+ polymorphic_derived2,
+ boost::serialization::extended_type_info_typeid<polymorphic_derived2>
+)
+
+BOOST_CLASS_EXPORT(polymorphic_derived2)
+
+const char * polymorphic_derived2::get_key() const {
+ // use the exported key as the identifier
+ const boost::serialization::extended_type_info *eti
+ = boost::serialization::type_info_implementation<polymorphic_derived2>
+ ::type::get_instance();
+ return eti->get_key();
+}
+
+// save derived polymorphic class
+void save_derived(const char *testfile)
+{
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
+
+ polymorphic_derived1 *rd1 = new polymorphic_derived1;
+ polymorphic_derived2 *rd2 = new polymorphic_derived2;
+
+ oa << BOOST_SERIALIZATION_NVP(rd1);
+ oa << BOOST_SERIALIZATION_NVP(rd2);
+
+ // the above opereration registers the derived classes as a side
+ // effect. Hence, instances can now be correctly serialized through
+ // a base class pointer.
+ polymorphic_base *rb1 = rd1;
+ polymorphic_base *rb2 = rd2;
+ oa << BOOST_SERIALIZATION_NVP(rb1);
+ oa << BOOST_SERIALIZATION_NVP(rb2);
+
+ delete rd1;
+ delete rd2;
+}
+
+// save derived polymorphic class
+void load_derived(const char *testfile)
+{
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
+
+ polymorphic_derived1 *rd1 = NULL;
+ polymorphic_derived2 *rd2 = NULL;
+
+ ia >> BOOST_SERIALIZATION_NVP(rd1);
+
+ BOOST_CHECK_MESSAGE(
+ boost::serialization::type_info_implementation<polymorphic_derived1>
+ ::type::get_instance()
+ == boost::serialization::type_info_implementation<polymorphic_derived1>
+ ::type::get_derived_extended_type_info(*rd1),
+ "restored pointer d1 not of correct type"
+ );
+
+ ia >> BOOST_SERIALIZATION_NVP(rd2);
+
+ BOOST_CHECK_MESSAGE(
+ boost::serialization::type_info_implementation<polymorphic_derived2>
+ ::type::get_instance()
+ == boost::serialization::type_info_implementation<polymorphic_derived2>
+ ::type::get_derived_extended_type_info(*rd2),
+ "restored pointer d2 not of correct type"
+ );
+
+ polymorphic_base *rb1 = NULL;
+ polymorphic_base *rb2 = NULL;
+
+ // the above opereration registers the derived classes as a side
+ // effect. Hence, instances can now be correctly serialized through
+ // a base class pointer.
+ ia >> BOOST_SERIALIZATION_NVP(rb1);
+
+ BOOST_CHECK_MESSAGE(
+ rb1 == dynamic_cast<polymorphic_base *>(rd1),
+ "serialized pointers not correctly restored"
+ );
+
+ BOOST_CHECK_MESSAGE(
+ boost::serialization::type_info_implementation<polymorphic_derived1>
+ ::type::get_instance()
+ == boost::serialization::type_info_implementation<polymorphic_base>
+ ::type::get_derived_extended_type_info(*rb1),
+ "restored pointer b1 not of correct type"
+ );
+
+ ia >> BOOST_SERIALIZATION_NVP(rb2);
+
+ BOOST_CHECK_MESSAGE(
+ rb2 == dynamic_cast<polymorphic_base *>(rd2),
+ "serialized pointers not correctly restored"
+ );
+
+ BOOST_CHECK_MESSAGE(
+ boost::serialization::type_info_implementation<polymorphic_derived2>
+ ::type::get_instance()
+ == boost::serialization::type_info_implementation<polymorphic_base>
+ ::type::get_derived_extended_type_info(*rb2),
+ "restored pointer b2 not of correct type"
+ );
+
+ delete rb1;
+ delete rb2;
+}
+
+int
+test_main( int /* argc */, char* /* argv */[] )
+{
+ const char * testfile = boost::archive::tmpnam(NULL);
+
+ BOOST_REQUIRE(NULL != testfile);
+
+ save_derived(testfile);
+ load_derived(testfile);
+
+ std::remove(testfile);
+ return EXIT_SUCCESS;
+}
+
+// EOF

Added: trunk/libs/serialization/performance/performance_polymorphic.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_polymorphic.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,104 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_polymorphic.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+// should pass compilation and execution
+
+#include <fstream>
+
+#include <cstdio> // remove
+#include <boost/config.hpp>
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::remove;
+}
+#endif
+
+#include "../test/test_tools.hpp"
+
+#if !defined(BOOST_ARCHIVE_TEST)
+#define BOOST_ARCHIVE_TEST polymorphic_text_archive.hpp
+#endif
+
+// the following is to ensure that when one of the libraries changes
+// BJAM rebuilds and relinks the test.
+/*
+#include "polymorphic_text_archive.hpp"
+#include "polymorphic_text_warchive.hpp"
+#include "polymorphic_binary_archive.hpp"
+#include "polymorphic_xml_archive.hpp"
+#include "polymorphic_xml_warchive.hpp"
+*/
+
+#include <boost/preprocessor/stringize.hpp>
+// #include <boost/preprocessor/cat.hpp>
+// the following fails with (only!) gcc 3.4
+// #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
+// just copy over the files from the test directory
+#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
+
+#include <boost/archive/polymorphic_oarchive.hpp>
+#include <boost/archive/polymorphic_iarchive.hpp>
+
+#include <boost/serialization/nvp.hpp>
+#include "../test/test_polymorphic_A.hpp"
+
+int test_main(int /* argc */, char * /* argv */ [])
+{
+ const char * testfile = boost::archive::tmpnam(NULL);
+ BOOST_REQUIRE(NULL != testfile);
+ const data d;
+ data d1;
+ // test using using polymorphic interface
+ {
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ test_oarchive oa_implementation(os);
+ boost::archive::polymorphic_oarchive & oa_interface = oa_implementation;
+ oa_interface << BOOST_SERIALIZATION_NVP(d);
+ }
+ {
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ test_iarchive ia_implementation(is);
+ boost::archive::polymorphic_iarchive & ia_interface = ia_implementation;
+ ia_interface >> BOOST_SERIALIZATION_NVP(d1);
+ }
+ BOOST_CHECK(d == d1);
+ std::remove(testfile);
+
+ // test using using polymorphic implementation.
+ {
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ test_oarchive oa_implementation(os);
+ oa_implementation << BOOST_SERIALIZATION_NVP(d);
+ }
+ {
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ test_iarchive ia_implementation(is);
+ ia_implementation >> BOOST_SERIALIZATION_NVP(d1);
+ }
+ BOOST_CHECK(d == d1);
+ std::remove(testfile);
+
+ // test using using polymorphic implementation.
+ {
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ boost::archive::polymorphic_oarchive * oa_implementation
+ = new test_oarchive(os);
+ *oa_implementation << BOOST_SERIALIZATION_NVP(d);
+ delete oa_implementation;
+ }
+ {
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ boost::archive::polymorphic_iarchive * ia_implementation
+ = new test_iarchive(is);
+ *ia_implementation >> BOOST_SERIALIZATION_NVP(d1);
+ delete ia_implementation;
+ }
+ BOOST_CHECK(d == d1);
+ std::remove(testfile);
+ return EXIT_SUCCESS;
+}

Added: trunk/libs/serialization/performance/performance_simple_class.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_simple_class.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,55 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_simple_class.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+// should pass compilation and execution
+
+// invoke header for a custom archive test.
+
+#include <fstream>
+
+#include <cstdio> // remove
+#include <boost/config.hpp>
+
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::remove;
+}
+#endif
+
+#include "../test/test_tools.hpp"
+#include <boost/preprocessor/stringize.hpp>
+// #include <boost/preprocessor/cat.hpp>
+// the following fails with (only!) gcc 3.4
+// #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
+// just copy over the files from the test directory
+#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
+
+#include <boost/serialization/nvp.hpp>
+#include "../test/A.hpp"
+
+int
+test_main( int /* argc */, char* /* argv */[] )
+{
+ const char * testfile = boost::archive::tmpnam(NULL);
+ BOOST_REQUIRE(NULL != testfile);
+
+ A a, a1;
+ {
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
+ oa << boost::serialization::make_nvp("a", a);
+ }
+ {
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
+ ia >> boost::serialization::make_nvp("a", a1);
+ }
+ BOOST_CHECK_EQUAL(a, a1);
+ std::remove(testfile);
+ return (a == a1) ? EXIT_SUCCESS : EXIT_SUCCESS;
+}

Added: trunk/libs/serialization/performance/performance_utf8_codecvt.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_utf8_codecvt.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,248 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_utf8_codecvt.cpp
+
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+#include <algorithm>
+#include <fstream>
+#include <iostream>
+#include <iterator>
+#include <locale>
+#include <vector>
+#include <string>
+
+#include <cstddef> // size_t
+#include <boost/config.hpp>
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::size_t;
+} // namespace std
+#endif
+
+#include <cwchar>
+#ifdef BOOST_NO_STDC_NAMESPACE
+namespace std{ using ::wcslen; }
+#endif
+
+#include "../test/test_tools.hpp"
+#include <boost/archive/iterators/istream_iterator.hpp>
+#include <boost/archive/iterators/ostream_iterator.hpp>
+
+#include <boost/archive/add_facet.hpp>
+#include <boost/archive/detail/utf8_codecvt_facet.hpp>
+
+template<std::size_t s>
+struct test_data
+{
+ static unsigned char utf8_encoding[];
+ static wchar_t wchar_encoding[];
+};
+
+template<>
+unsigned char test_data<2>::utf8_encoding[] = {
+ 0x01,
+ 0x7f,
+ 0xc2, 0x80,
+ 0xdf, 0xbf,
+ 0xe0, 0xa0, 0x80,
+ 0xe7, 0xbf, 0xbf
+};
+
+template<>
+wchar_t test_data<2>::wchar_encoding[] = {
+ 0x0001,
+ 0x007f,
+ 0x0080,
+ 0x07ff,
+ 0x0800,
+ 0x7fff
+};
+
+template<>
+unsigned char test_data<4>::utf8_encoding[] = {
+ 0x01,
+ 0x7f,
+ 0xc2, 0x80,
+ 0xdf, 0xbf,
+ 0xe0, 0xa0, 0x80,
+ 0xef, 0xbf, 0xbf,
+ 0xf0, 0x90, 0x80, 0x80,
+ 0xf4, 0x8f, 0xbf, 0xbf,
+ 0xf7, 0xbf, 0xbf, 0xbf,
+ 0xf8, 0x88, 0x80, 0x80, 0x80,
+ 0xfb, 0xbf, 0xbf, 0xbf, 0xbf,
+ 0xfc, 0x84, 0x80, 0x80, 0x80, 0x80,
+ 0xfd, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf
+};
+
+template<>
+wchar_t test_data<4>::wchar_encoding[] = {
+ 0x00000001,
+ 0x0000007f,
+ 0x00000080,
+ 0x000007ff,
+ 0x00000800,
+ 0x0000ffff,
+ 0x00010000,
+ 0x0010ffff,
+ 0x001fffff,
+ 0x00200000,
+ 0x03ffffff,
+ 0x04000000,
+ 0x7fffffff
+};
+
+int
+test_main(int /* argc */, char * /* argv */[]) {
+ std::locale old_loc;
+ std::locale * utf8_locale
+ = boost::archive::add_facet(
+ old_loc,
+ new boost::archive::detail::utf8_codecvt_facet
+ );
+
+ typedef char utf8_t;
+ typedef test_data<sizeof(wchar_t)> td;
+
+ // Send our test UTF-8 data to file
+ {
+ std::ofstream ofs;
+ ofs.open("test.dat", std::ios::binary);
+ std::copy(
+ td::utf8_encoding,
+ #if ! defined(__BORLANDC__)
+ // borland 5.60 complains about this
+ td::utf8_encoding + sizeof(td::utf8_encoding) / sizeof(unsigned char),
+ #else
+ // so use this instead
+ td::utf8_encoding + 12,
+ #endif
+ boost::archive::iterators::ostream_iterator<utf8_t>(ofs)
+ );
+ }
+
+ // Read the test data back in, converting to UCS-4 on the way in
+ std::vector<wchar_t> from_file;
+ {
+ std::wifstream ifs;
+ ifs.imbue(*utf8_locale);
+ ifs.open("test.dat");
+
+ wchar_t item = 0;
+ // note can't use normal vector from iterator constructor because
+ // dinkumware doesn't have it.
+ for(;;){
+ item = ifs.get();
+ if(item == WEOF)
+ break;
+ //ifs >> item;
+ //if(ifs.eof())
+ // break;
+ from_file.push_back(item);
+ }
+ }
+
+ // compare the data read back in with the orginal
+ #if ! defined(__BORLANDC__)
+ // borland 5.60 complains about this
+ BOOST_CHECK(from_file.size() == sizeof(td::wchar_encoding)/sizeof(wchar_t));
+ #else
+ // so use this instead
+ BOOST_CHECK(from_file.size() == 6);
+ #endif
+
+ BOOST_CHECK(std::equal(from_file.begin(), from_file.end(), td::wchar_encoding));
+
+ // Send the UCS4_data back out, converting to UTF-8
+ {
+ std::wofstream ofs;
+ ofs.imbue(*utf8_locale);
+ ofs.open("test2.dat");
+ std::copy(
+ from_file.begin(),
+ from_file.end(),
+ boost::archive::iterators::ostream_iterator<wchar_t>(ofs)
+ );
+ }
+
+ // Make sure that both files are the same
+ {
+ typedef boost::archive::iterators::istream_iterator<utf8_t> is_iter;
+ is_iter end_iter;
+
+ std::ifstream ifs1("test.dat");
+ is_iter it1(ifs1);
+ std::vector<utf8_t> data1;
+ std::copy(it1, end_iter, std::back_inserter(data1));
+
+ std::ifstream ifs2("test2.dat");
+ is_iter it2(ifs2);
+ std::vector<utf8_t> data2;
+ std::copy(it2, end_iter, std::back_inserter(data2));
+
+ BOOST_CHECK(data1 == data2);
+ }
+
+ // some libraries have trouble that only shows up with longer strings
+
+ wchar_t * test3_data = L"\
+ <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\
+ <!DOCTYPE boost_serialization>\
+ <boost_serialization signature=\"serialization::archive\" version=\"3\">\
+ <a class_id=\"0\" tracking_level=\"0\">\
+ <b>1</b>\
+ <f>96953204</f>\
+ <g>177129195</g>\
+ <l>1</l>\
+ <m>5627</m>\
+ <n>23010</n>\
+ <o>7419</o>\
+ <p>16212</p>\
+ <q>4086</q>\
+ <r>2749</r>\
+ <c>-33</c>\
+ <s>124</s>\
+ <t>28</t>\
+ <u>32225</u>\
+ <v>17543</v>\
+ <w>0.84431422</w>\
+ <x>1.0170664757130923</x>\
+ <y>tjbx</y>\
+ <z>cuwjentqpkejp</z>\
+ </a>\
+ </boost_serialization>\
+ ";
+
+ // Send the UCS4_data back out, converting to UTF-8
+ std::size_t l = std::wcslen(test3_data);
+ {
+ std::wofstream ofs;
+ ofs.imbue(*utf8_locale);
+ ofs.open("test3.dat");
+ std::copy(
+ test3_data,
+ test3_data + l,
+ boost::archive::iterators::ostream_iterator<wchar_t>(ofs)
+ );
+ }
+
+ // Make sure that both files are the same
+ {
+ std::wifstream ifs;
+ ifs.imbue(*utf8_locale);
+ ifs.open("test3.dat");
+ BOOST_CHECK(
+ std::equal(
+ test3_data,
+ test3_data + l,
+ boost::archive::iterators::istream_iterator<wchar_t>(ifs)
+ )
+ );
+ }
+
+ delete utf8_locale;
+ return EXIT_SUCCESS;
+}

Added: trunk/libs/serialization/performance/performance_vector.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/performance_vector.cpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,70 @@
+/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
+// test_vector.cpp
+
+// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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)
+
+// should pass compilation and execution
+
+#include <fstream>
+
+#include <cstdio> // remove
+#include <boost/config.hpp>
+#if defined(BOOST_NO_STDC_NAMESPACE)
+namespace std{
+ using ::remove;
+}
+#endif
+
+#include "../test/test_tools.hpp"
+#include <boost/preprocessor/stringize.hpp>
+// #include <boost/preprocessor/cat.hpp>
+// the following fails with (only!) gcc 3.4
+// #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
+// just copy over the files from the test directory
+#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
+#include <boost/serialization/vector.hpp>
+
+#include "../test/A.hpp"
+
+template <class T>
+int test_vector(T)
+{
+ const char * testfile = boost::archive::tmpnam(NULL);
+ BOOST_REQUIRE(NULL != testfile);
+
+ // test array of objects
+ std::vector<T> avector;
+ avector.push_back(T());
+ avector.push_back(T());
+ {
+ test_ostream os(testfile, TEST_STREAM_FLAGS);
+ test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
+ oa << boost::serialization::make_nvp("avector", avector);
+ }
+ std::vector<T> avector1;
+ {
+ test_istream is(testfile, TEST_STREAM_FLAGS);
+ test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
+ ia >> boost::serialization::make_nvp("avector", avector1);
+ }
+ BOOST_CHECK(avector == avector1);
+ std::remove(testfile);
+ return EXIT_SUCCESS;
+}
+
+int test_main( int /* argc */, char* /* argv */[] )
+{
+ int res = test_vector(A());
+ // test an int vector for which optimized versions should be available
+ if (res == EXIT_SUCCESS)
+ res = test_vector(0);
+ // test a bool vector
+ if (res == EXIT_SUCCESS)
+ res = test_vector(false);
+ return res;
+}
+
+// EOF

Added: trunk/libs/serialization/performance/polymorphic_array_binary_archive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/polymorphic_array_binary_archive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,13 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+#include <boost/archive/polymorphic_binary_oarchive.hpp>
+typedef boost::archive::polymorphic_binary_oarchive test_oarchive;
+typedef std::ofstream test_ostream;
+#include <boost/archive/polymorphic_binary_iarchive.hpp>
+typedef boost::archive::polymorphic_binary_iarchive test_iarchive;
+typedef std::ifstream test_istream;
+#define TEST_STREAM_FLAGS std::ios::binary

Added: trunk/libs/serialization/performance/polymorphic_binary_archive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/polymorphic_binary_archive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,13 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+#include <boost/archive/polymorphic_binary_oarchive.hpp>
+typedef boost::archive::polymorphic_binary_oarchive test_oarchive;
+typedef std::ofstream test_ostream;
+#include <boost/archive/polymorphic_binary_iarchive.hpp>
+typedef boost::archive::polymorphic_binary_iarchive test_iarchive;
+typedef std::ifstream test_istream;
+#define TEST_STREAM_FLAGS std::ios::binary

Added: trunk/libs/serialization/performance/polymorphic_text_archive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/polymorphic_text_archive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,13 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+#include <boost/archive/polymorphic_text_oarchive.hpp>
+typedef boost::archive::polymorphic_text_oarchive test_oarchive;
+typedef std::ofstream test_ostream;
+#include <boost/archive/polymorphic_text_iarchive.hpp>
+typedef boost::archive::polymorphic_text_iarchive test_iarchive;
+typedef std::ifstream test_istream;
+#define TEST_STREAM_FLAGS (std::ios_base::openmode)0

Added: trunk/libs/serialization/performance/polymorphic_text_warchive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/polymorphic_text_warchive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,18 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+#include <boost/config.hpp>
+#ifdef BOOST_NO_STD_WSTREAMBUF
+#error "wide char i/o not supported on this platform"
+#else
+#include <boost/archive/polymorphic_text_woarchive.hpp>
+typedef boost::archive::polymorphic_text_woarchive test_oarchive;
+typedef std::wofstream test_ostream;
+#include <boost/archive/polymorphic_text_wiarchive.hpp>
+typedef boost::archive::polymorphic_text_wiarchive test_iarchive;
+typedef std::wifstream test_istream;
+#define TEST_STREAM_FLAGS (std::ios_base::openmode)0
+#endif
\ No newline at end of file

Added: trunk/libs/serialization/performance/polymorphic_xml_archive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/polymorphic_xml_archive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,13 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+#include <boost/archive/polymorphic_xml_oarchive.hpp>
+typedef boost::archive::polymorphic_xml_oarchive test_oarchive;
+typedef std::ofstream test_ostream;
+#include <boost/archive/polymorphic_xml_iarchive.hpp>
+typedef boost::archive::polymorphic_xml_iarchive test_iarchive;
+typedef std::ifstream test_istream;
+#define TEST_STREAM_FLAGS (std::ios_base::openmode)0

Added: trunk/libs/serialization/performance/polymorphic_xml_warchive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/polymorphic_xml_warchive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,13 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+#include <boost/archive/polymorphic_xml_woarchive.hpp>
+typedef boost::archive::polymorphic_xml_woarchive test_oarchive;
+typedef std::wofstream test_ostream;
+#include <boost/archive/polymorphic_xml_wiarchive.hpp>
+typedef boost::archive::polymorphic_xml_wiarchive test_iarchive;
+typedef std::wifstream test_istream;
+#define TEST_STREAM_FLAGS (std::ios_base::openmode)0

Added: trunk/libs/serialization/performance/portable_binary_archive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/portable_binary_archive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,22 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.// file includes for testing a custom archive.
+// as an example this tests the portable binary archive
+
+// #include output archive header
+#include "../example/portable_binary_oarchive.hpp"
+// define output archive class to be used
+typedef portable_binary_oarchive test_oarchive;
+// and corresponding stream
+typedef std::ofstream test_ostream;
+
+// repeat the above for correspondng input archive
+#include "../example/portable_binary_iarchive.hpp"
+typedef portable_binary_iarchive test_iarchive;
+typedef std::ifstream test_istream;
+
+// and stream open flags
+#define TEST_STREAM_FLAGS std::ios::binary

Added: trunk/libs/serialization/performance/profile.sh
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/profile.sh 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,34 @@
+# build and run the tests leaving the executables in place
+
+# runtest.sh --toolset=gcc --preserve-test-targets variant=profile
+if test $# -eq 0
+then
+ echo "Usage: $0 <bjam arguments>"
+ echo "Typical bjam arguements are:"
+ echo " --toolset=msvc-7.1,gcc"
+ echo " link=static,shared"
+ echo " threading=single,multi"
+ echo " -sBOOST_ARCHIVE_LIST=<archive name>"
+else
+ bjam --dump-tests --preserve-test-targets variant=profile $@ >bjam.log 2>&1
+ process_jam_log --v2 <bjam.log
+
+ # for each test directory
+
+ for dir in \
+ ../../../bin.v2/libs/serialization/performance/*/gcc*/profile \
+ ../../../bin.v2/libs/serialization/performance/*/gcc*/*/profile
+ do
+ # execute test
+ for exe in $dir/*.exe
+ do
+ # execute the test
+ echo executing $exe
+ $exe
+ # copy profile to test directory
+ gprof $exe gmon.out >$dir/profile.txt
+ done
+ done
+
+ library_status library_status.html links.html
+fi

Added: trunk/libs/serialization/performance/text_archive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/text_archive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,14 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+// text_archive
+#include <boost/archive/text_oarchive.hpp>
+typedef boost::archive::text_oarchive test_oarchive;
+typedef std::ofstream test_ostream;
+#include <boost/archive/text_iarchive.hpp>
+typedef boost::archive::text_iarchive test_iarchive;
+typedef std::ifstream test_istream;
+#define TEST_STREAM_FLAGS (std::ios_base::openmode)0

Added: trunk/libs/serialization/performance/text_warchive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/text_warchive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,19 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+// text_warchive
+#include <boost/archive/text_woarchive.hpp>
+typedef boost::archive::text_woarchive test_oarchive;
+typedef std::wofstream test_ostream;
+#include <boost/archive/text_wiarchive.hpp>
+typedef boost::archive::text_wiarchive test_iarchive;
+typedef std::wifstream test_istream;
+#define TEST_STREAM_FLAGS (std::ios_base::openmode)0
+
+
+
+
+

Added: trunk/libs/serialization/performance/xml_archive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/xml_archive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,16 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+// xml_archive
+#include <boost/archive/xml_oarchive.hpp>
+typedef boost::archive::xml_oarchive test_oarchive;
+typedef std::ofstream test_ostream;
+#include <boost/archive/xml_iarchive.hpp>
+typedef boost::archive::xml_iarchive test_iarchive;
+typedef std::ifstream test_istream;
+#define TEST_STREAM_FLAGS (std::ios_base::openmode)0
+
+

Added: trunk/libs/serialization/performance/xml_warchive.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/serialization/performance/xml_warchive.hpp 2008-06-10 00:28:34 EDT (Tue, 10 Jun 2008)
@@ -0,0 +1,16 @@
+// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
+// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
+// xml_warchive
+#include <boost/archive/xml_woarchive.hpp>
+typedef boost::archive::xml_woarchive test_oarchive;
+typedef std::wofstream test_ostream;
+#include <boost/archive/xml_wiarchive.hpp>
+typedef boost::archive::xml_wiarchive test_iarchive;
+typedef std::wifstream test_istream;
+#define TEST_STREAM_FLAGS (std::ios_base::openmode)0
+
+


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