msgpack deserialization performance comparison (C ++ / Python / Ruby)

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.

Measurement environment

Measuring method

--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

Code used for measurement

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

msgpack deserialization performance comparison (C ++ / Python / Ruby)
Python, Java, C ++ speed comparison
Five languages basic grammar comparison (C #, Java, Python, Ruby, Kotlin)
Multi-stage selection (Go / C # / Ruby / Python)
Call popcount from Ruby / Python / C #
Closure 4 language comparison (Python, JavaScript, Java, C ++)
Big difference in ruby, python, httpd performance
First Python 3 ~ First comparison ~
Performance comparison of face detector with Python + OpenCV
python C ++ notes
python, openFrameworks (c ++)
paiza POH ec-campaign (C # / Java / Python / Ruby) # paizahack_01
Comparison of Python and Ruby (Environment / Grammar / Literal)
[Ruby vs Python] Benchmark comparison between Rails and Flask
Comparison of CoffeeScript with JavaScript, Python and Ruby grammar
Python SDP runtime comparison
Python C / C ++ Extension Pattern-Pointer
Ruby, Python and map
Next Python in C
Python and Ruby split
Python package manager comparison
C API in Python 3
ABC147 C --HonestOrUnkind2 [Python]
Solving with Ruby and Python AtCoder ARC 059 C Least Squares
Python Web framework performance comparison (Django, Flask, responder, FastAPI, japronto)
Mandelbrot Benchmark (C, PHP, HHVM, Ruby, Python, PyPy, and Kinx)
Solving with Ruby and Python AtCoder ABC011 C Dynamic programming
Solving with Ruby and Python AtCoder ARC067 C Prime Factorization
AtCoder ABC151 Problem D Speed comparison in C ++ / Python / PyPy
Ruby vs Python Performance. How to pick the right technology?