1 /* /libs/serialization/xml_performance/macro.hpp *******************************
3 (C) Copyright 2010 Bryce Lelbach
5 Use, modification and distribution is subject to the Boost Software License,
6 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
9 *******************************************************************************/
11 #if !defined(BOOST_SERIALIZATION_XML_PERFORMANCE_MACRO_HPP)
12 #define BOOST_SERIALIZATION_XML_PERFORMANCE_MACRO_HPP
18 #include <boost/preprocessor.hpp>
20 #if !defined(BSL_NODE_MAX)
21 #define BSL_NODE_MAX 4
24 #if !defined(BSL_DEPTH)
28 #if !defined(BSL_ROUNDS)
29 #define BSL_ROUNDS 256
32 #if !defined(BSL_TYPE)
36 #if !defined(BSL_SAVE_TMPFILE)
37 #define BSL_SAVE_TMPFILE 0
40 #if !defined(BSL_RESULTS_FILE)
41 #define BSL_RESULTS_FILE \
42 BOOST_PP_STRINGIZE(BSL_TYPE) \
43 BOOST_PP_STRINGIZE(BSL_EXP(BSL_NODE_MAX, BSL_DEPTH)) \
48 // utility print macro
50 #define BSL_PRINT(Z, N, T) T
52 // preprocessor power function, BSL_EXP
54 #define BSL_EXP_PRED(B, D) BOOST_PP_TUPLE_ELEM(3, 0, D)
56 #define BSL_EXP_OP(B, D) \
58 BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(3, 0, D)), \
59 BOOST_PP_TUPLE_ELEM(3, 1, D), \
62 BOOST_PP_TUPLE_ELEM(3, 2, D), \
63 BOOST_PP_TUPLE_ELEM(3, 1, D) \
68 #define BSL_EXP(X, N) \
69 BOOST_PP_TUPLE_ELEM( \
70 3, 2, BOOST_PP_WHILE(BSL_EXP_PRED, BSL_EXP_OP, (N, X, 1)) \
74 // boost::archive::xml::node macros
76 #define BSL_NODE_DECL_MEMBER(Z, N, _) T ## N element ## N ;
77 #define BSL_NODE_DECL_NONE(Z, N, _) unused_type element ## N ;
78 #define BSL_NODE_xDECL_CTOR() node (void) { }
80 #define BSL_NODE_DECL_CTOR(P) \
82 BSL_NODE_xDECL_CTOR, \
87 #define BSL_NODE_SERIALIZE(Z, N, _) \
88 & BOOST_SERIALIZATION_NVP(BOOST_PP_CAT(element, N)) \
91 #define BSL_NODE_INIT_LIST(Z, N, _) \
92 BOOST_PP_COMMA_IF(N) BOOST_PP_CAT(element, N) \
93 BOOST_PP_LPAREN() BOOST_PP_CAT(p, N) BOOST_PP_RPAREN() \
96 #define BSL_NODE_DECL(Z, N, _) \
97 template<BOOST_PP_ENUM_PARAMS_Z(Z, N, typename T)> \
99 BOOST_PP_ENUM_PARAMS_Z(Z, N, T) \
100 BOOST_PP_COMMA_IF(N) \
101 BOOST_PP_ENUM_ ## Z(BOOST_PP_SUB(BSL_NODE_MAX, N), BSL_PRINT, unused_type) \
103 BOOST_PP_REPEAT_ ## Z(N, BSL_NODE_DECL_MEMBER, _) \
105 BOOST_PP_REPEAT_FROM_TO_ ## Z(N, BSL_NODE_MAX, BSL_NODE_DECL_NONE, _) \
107 template<class ARC> \
108 void serialize (ARC& ar, const unsigned int) { \
109 ar BOOST_PP_REPEAT_ ## Z(N, BSL_NODE_SERIALIZE, _); \
112 BSL_NODE_DECL_CTOR(N) \
114 node (BOOST_PP_ENUM_BINARY_PARAMS_Z(Z, N, T, p)): \
115 BOOST_PP_REPEAT_ ## Z(N, BSL_NODE_INIT_LIST, _) { } \
119 // instantiation macros
121 #define BSL_INST_BASE(Z, N, L) \
122 T0 T0 ## _ ## N(BOOST_PP_ENUM_ ## Z( \
123 BSL_NODE_MAX, BSL_PRINT, \
124 boost::archive::xml::random<BSL_TYPE> BOOST_PP_LPAREN() BOOST_PP_RPAREN() \
128 #define BSL_INST_yNODES(Z, N, L) \
129 BOOST_PP_COMMA_IF(N) \
131 BOOST_PP_CAT(BOOST_PP_LIST_AT(L, 1), \
134 BOOST_PP_LIST_AT(L, 0) \
141 #define BSL_INST_xNODES(Z, N, L) \
142 T ## L T ## L ## _ ## N( \
143 BOOST_PP_REPEAT_ ## Z( \
144 BSL_NODE_MAX, BSL_INST_yNODES, \
145 (BOOST_PP_MUL(N, BSL_NODE_MAX), (BOOST_PP_SUB(L, 1), BOOST_PP_NIL)) \
150 #define BSL_INST_NODES(Z, N, L) \
151 BOOST_PP_REPEAT_ ## Z( \
152 BSL_EXP(BSL_NODE_MAX, BOOST_PP_SUB(BSL_DEPTH, N)), \
157 #define BSL_TYPEDEF_NODES(Z, N, L) \
158 typedef boost::archive::xml::node< \
159 BOOST_PP_ENUM_ ## Z( \
160 BSL_NODE_MAX, BSL_PRINT, BOOST_PP_CAT(T, BOOST_PP_SUB(N, 1)) \
169 using namespace boost::archive; \
170 using namespace boost::archive::xml; \
172 typedef node<BOOST_PP_ENUM(BSL_NODE_MAX, BSL_PRINT, BSL_TYPE)> T0; \
174 BOOST_PP_REPEAT_FROM_TO(1, BSL_DEPTH, BSL_TYPEDEF_NODES, _) \
176 typedef node<BOOST_PP_ENUM( \
177 BSL_NODE_MAX, BSL_PRINT, \
178 BOOST_PP_CAT(T, BOOST_PP_SUB(BSL_DEPTH, 1)) \
181 result_set results; \
182 std::size_t rounds = BSL_ROUNDS; \
184 while (rounds --> 0) { \
185 BOOST_PP_REPEAT(BSL_EXP(BSL_NODE_MAX, BSL_DEPTH), BSL_INST_BASE, _) \
187 BOOST_PP_REPEAT_FROM_TO(1, BSL_DEPTH, BSL_INST_NODES, _) \
189 HEAD h(BOOST_PP_ENUM_PARAMS( \
191 BOOST_PP_CAT(T, BOOST_PP_CAT(BOOST_PP_SUB(BSL_DEPTH, 1), _)) \
194 std::string fn = save_archive(h); \
196 std::pair<double, HEAD> r = restore_archive<HEAD>(fn); \
198 std::cout << "round " \
199 << ((BSL_ROUNDS - 1) - rounds) \
200 << " -> " << fn << "\n"; \
202 BOOST_PP_IF(BSL_SAVE_TMPFILE, \
204 std::remove(fn.c_str()); \
207 results.entries.push_back(entry( \
208 BOOST_PP_STRINGIZE(BSL_TYPE), \
209 BSL_EXP(BSL_NODE_MAX, BSL_DEPTH), r.first \
213 std::fstream fs(BSL_RESULTS_FILE, std::fstream::in); \
216 xml_iarchive ia(fs); \
217 ia >> BOOST_SERIALIZATION_NVP(results); \
221 fs.open(BSL_RESULTS_FILE, std::fstream::out | std::fstream::trunc); \
222 xml_oarchive oa(fs); \
223 oa << BOOST_SERIALIZATION_NVP(results); \
229 #endif // BOOST_SERIALIZATION_XML_PERFORMANCE_MACRO_HPP