/* /libs/serialization/xml_performance/harness.hpp ***************************** (C) Copyright 2010 Bryce Lelbach 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) *******************************************************************************/ #if !defined(BOOST_SERIALIZATION_XML_PERFORMANCE_HARNESS_HPP) #define BOOST_SERIALIZATION_XML_PERFORMANCE_HARNESS_HPP // MS compatible compilers support #pragma once #if defined(_MSC_VER) # pragma once #endif #include #include #include #include #include #include #include #if defined(BOOST_NO_STDC_NAMESPACE) namespace std { using ::remove; } #endif #include #include #include #include #include #include #include #include #include #include "high_resolution_timer.hpp" // from /libs/spirit/optimization #include "node.hpp" // includes macro.hpp namespace boost { namespace archive { namespace xml { template T random (void); template T random (void) { using namespace boost::uuids; hash hash; basic_random_generator gen; return hash(gen()); } template<> std::string random (void) { using namespace boost::uuids; basic_random_generator gen; uuid u = gen(); return to_string(u); } template std::string save_archive (T const& s) { std::string fn = random() + "-" BOOST_PP_STRINGIZE(BSL_TYPE) BOOST_PP_STRINGIZE(BSL_EXP(BSL_NODE_MAX, BSL_DEPTH)) ".xml" ; std::ofstream ofs(fn.c_str()); assert(ofs.good()); xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(s); ofs.close(); return fn; } template std::pair restore_archive (std::string fn) { std::ifstream ifs(fn.c_str()); T s; assert(ifs.good()); high_resolution_timer u; xml_iarchive ia(ifs); ia >> BOOST_SERIALIZATION_NVP(s); ifs.close(); return std::pair(u.elapsed(), s); } class result_set_exception: public virtual archive_exception { public: enum exception_code { invalid_archive_metadata }; result_set_exception (exception_code c = invalid_archive_metadata){ } virtual const char* what() const throw() { const char *msg = ""; switch (code) { case invalid_archive_metadata: msg = "result set was not created on this system"; default: archive_exception::what(); } return msg; } }; struct entry { std::string type; std::size_t size; double data; template void serialize (ARC& ar, const unsigned int) { ar & BOOST_SERIALIZATION_NVP(type) & BOOST_SERIALIZATION_NVP(size) & BOOST_SERIALIZATION_NVP(data) ; } entry (void) { } entry (std::string type, std::size_t size, double data): type(type), size(size), data(data) { } }; struct result_set { std::string compiler; std::string platform; std::list entries; template void serialize (ARC& ar, const unsigned int) { ar & BOOST_SERIALIZATION_NVP(compiler) & BOOST_SERIALIZATION_NVP(platform) & BOOST_SERIALIZATION_NVP(entries) ; if ( (compiler != BOOST_COMPILER) || (platform != BOOST_PLATFORM)) throw result_set_exception(); } result_set (void): compiler(BOOST_COMPILER), platform(BOOST_PLATFORM) { } result_set (std::list entries): compiler(BOOST_COMPILER), platform(BOOST_PLATFORM), entries(entries) { } }; } // xml } // archive } // boost #endif // BOOST_SERIALIZATION_XML_PERFORMANCE_HARNESS_HPP