I investigated the performance of reading using each msgpack library in C ++, Python, and Ruby. I didn't ask for rigor, but I wanted to get a rough sense of performance, so I didn't make any fine adjustments. The following is the performance when reading 10,000,000 messages with standard input.
| environment | user time | sys time | total | performance | 
|---|---|---|---|---|
| C++ (Apple LLVM version 6.1.0 (clang-602.0.53) + msgpack-c 1.2.0) | 6.13s | 1.38s | 7.649 | 1,307,360.43 msg/sec | 
| Python (Python 2.7.6 +,msgpack-python 0.4.6) | 17.50s | 1.62s | 20.561 | 486,357.66 msg/sec | 
| Ruby (2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] + msgpack-ruby 0.6.2) | 26.67s | 0.95s | 27.729 | 360,633.27 msg/sec | 
Below are the details.
--Read 10,000,000 messages with standard input. --Check if the read message is an Array and count it --Time command to measure execution time --List the shortest execution time after executing several times
C++
#include <msgpack.hpp>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <time.h>
int main(int argc, char *argv[]) {
  static const size_t BUFSIZE = 4096;
  msgpack::unpacker unpkr;
  int rc;
  int array_count = 0;
  
  char buf[BUFSIZE];
  while (0 < (rc = read(0, buf, sizeof(buf)))) {
    unpkr.reserve_buffer(rc);
    memcpy(unpkr.buffer(), buf, rc);
    unpkr.buffer_consumed(rc);
    msgpack::unpacked result;
    while (unpkr.next(&result)) {
      const msgpack::object &obj = result.get();
      if (obj.type == msgpack::type::ARRAY) {
        array_count++;
      }
      result.zone().reset();
    }
  }
  printf("%d\n", array_count);
  return 0;
}
Python
#!/usr/bin/env python
import msgpack
import sys
array_count = 0
for msg in msgpack.Unpacker(sys.stdin):
    if isinstance(msg, list): array_count += 1
print array_count
Ruby
#!/usr/bin/env ruby
require 'msgpack'
array_count = 0
unpkr = MessagePack::Unpacker.new(STDIN)
unpkr.each do |msg|
  if msg.instance_of? Array
    array_count += 1
  end
end
puts array_count
        Recommended Posts