ZIO
Python and C++ interface to ZeroMQ and Zyre
test_msgmsg.cpp
Go to the documentation of this file.
1 // Test the speed of msg churn needed to encode/decode multi frame
2 // messages into single frame messages.
3 
4 #include "zio/cppzmq.hpp"
5 #include "zio/util.hpp"
6 #include "zio/main.hpp"
7 #include "zio/logging.hpp"
8 #include <vector>
9 
10 
11 
12 int main()
13 {
14  zio::init_all();
15 
16  const int HEADERSIZE=32;
17  char* header[HEADERSIZE] = {0};
18  const int NTRY = 10000;
19  const int MAXSIZE = 1<<17;
20  int size = 2;
21  const auto t0 = zio::now_us();
22  while (size <= MAXSIZE) {
23  const auto t1 = zio::now_us();
24  std::vector<char> buf(size);
25  for (int count=0; count<NTRY; ++count) {
26  zio::multipart_t mmsg;
27  mmsg.addmem(header, HEADERSIZE);
28  mmsg.addmem(buf.data(), size);
29  auto msg = mmsg.encode();
30 
31  auto mmsg2 = zio::multipart_t::decode(msg);
32  }
33  const auto t2 = zio::now_us();
34  const auto dt = (t2-t1).count();
35  zio::debug("size: {} in {} usec {} kHz", size, dt, (1000.0*NTRY)/dt);
36  size *= 2;
37  }
38  const auto t3 = zio::now_us();
39  const auto tott = 1e-6*(t3-t0).count();
40  zio::debug("{} sec", tott);
41 
42  return 0;
43 }
int main()
Definition: test_msgmsg.cpp:12
void init_all()
Definition: main.cpp:22
std::chrono::microseconds now_us()
Definition: util.cpp:178