17
17
18
18
#include " boost/record.hpp"
19
19
20
+ #include " msgpack/record.hpp"
21
+
20
22
const size_t kItegersCount = 1000 ;
21
23
const size_t kStringsCount = 100 ;
22
24
const int64_t kIntegerValue = 26354 ;
@@ -155,6 +157,55 @@ boost_serialization_test(size_t iterations)
155
157
std::cout << " boost: time = " << duration << " milliseconds" << std::endl << std::endl;
156
158
}
157
159
160
+ void
161
+ msgpack_serialization_test (size_t iterations)
162
+ {
163
+ using namespace msgpack_test ;
164
+
165
+ Record r1, r2;
166
+
167
+ for (size_t i = 0 ; i < kItegersCount ; i++) {
168
+ r1.ids .push_back (kIntegerValue );
169
+ }
170
+
171
+ for (size_t i = 0 ; i < kStringsCount ; i++) {
172
+ r1.strings .push_back (kStringValue );
173
+ }
174
+
175
+ msgpack::sbuffer sbuf;
176
+
177
+ msgpack::pack (sbuf, r1);
178
+
179
+ std::string serialized (sbuf.data (), sbuf.size ());
180
+
181
+ msgpack::unpacked msg;
182
+ msgpack::unpack (&msg, serialized.data (), serialized.size ());
183
+
184
+ msgpack::object obj = msg.get ();
185
+
186
+ obj.convert (&r2);
187
+
188
+ if (r1 != r2) {
189
+ throw std::logic_error (" msgpack's case: deserialization failed" );
190
+ }
191
+
192
+ std::cout << " msgpack: size = " << serialized.size () << " bytes" << std::endl;
193
+
194
+ auto start = std::chrono::high_resolution_clock::now ();
195
+ for (size_t i = 0 ; i < iterations; i++) {
196
+ sbuf.clear ();
197
+ msgpack::pack (sbuf, r1);
198
+ msgpack::unpacked msg;
199
+ msgpack::unpack (&msg, sbuf.data (), sbuf.size ());
200
+ msgpack::object obj = msg.get ();
201
+ obj.convert (&r2);
202
+ }
203
+ auto finish = std::chrono::high_resolution_clock::now ();
204
+ auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count ();
205
+
206
+ std::cout << " msgpack: time = " << duration << " milliseconds" << std::endl << std::endl;
207
+ }
208
+
158
209
int
159
210
main (int argc, char **argv)
160
211
{
@@ -175,6 +226,7 @@ main(int argc, char **argv)
175
226
thrift_serialization_test (iterations);
176
227
protobuf_serialization_test (iterations);
177
228
boost_serialization_test (iterations);
229
+ msgpack_serialization_test (iterations);
178
230
} catch (std::exception &exc) {
179
231
std::cerr << " Error: " << exc.what () << std::endl;
180
232
return EXIT_FAILURE;
0 commit comments