J'ai étudié les performances de lecture en utilisant chaque bibliothèque msgpack en C ++, Python et Ruby. Je n'ai pas demandé de rigueur, mais je voulais avoir une idée approximative de la performance, donc je n'ai pas fait de réglages fins. Voici les performances lors de la lecture de 10 000 000 messages avec une entrée standard.
environnement | 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 |
Voici les détails.
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