{"id":2937,"date":"2019-11-25T17:30:37","date_gmt":"2019-11-25T16:30:37","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=2937"},"modified":"2021-02-18T09:06:05","modified_gmt":"2021-02-18T08:06:05","slug":"messagepack-test","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/messagepack-test\/","title":{"rendered":"MessagePack test"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const Promise = require(\"bluebird\");\nconst fsNode = require(\"fs\");\nconst fs = Promise.promisifyAll(fsNode);\nconst msgpack = require(\"msgpack-lite\");\n\nprocess.on('unhandledRejection', (reason, promise) => {\n\tconsole.log('Unhandled Rejection at:', promise, 'reason:', reason);\n});\n\nprocess.on('uncaughtException', (err, origin) => {\n\tconsole.log(\n\t\tprocess.stderr.fd,\n\t\t`Caught exception: ${err}\\n` +\n\t\t`Exception origin: ${origin}`\n\t);\n});\n\nfunction run() {\n\treturn fs.readFileAsync(\"data.json\")\n\t\t.then(data => {\n\t\t\tconsole.time(\"json-decode\")\n\t\t\tconst obj = JSON.parse(data);\n\t\t\tconsole.timeEnd(\"json-decode\")\n\n\t\t\tconsole.time(\"json-encode\")\n\t\t\tconst str = JSON.stringify(obj);\n\t\t\tconsole.timeEnd(\"json-encode\")\n\t\t\tconsole.log(str.length);\n\n\t\t\tconsole.time(\"encode\");\n\t\t\tconst str2 = msgpack.encode(obj)\n\t\t\tconsole.timeEnd(\"encode\")\n\t\t\tconsole.log(str2.length);\n\n\t\t\tconsole.time(\"decode\");\n\t\t\tconst msgpk = msgpack.decode(str2);\n\t\t\tconsole.timeEnd(\"decode\");\n\t\t});\n};\n\nrun();\n\n\/*\njson-decode: 60.222ms\njson-encode: 43.728ms\n9172547\nencode: 166.285ms\n7818978\ndecode: 313.279ms\n*\/\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2937","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=2937"}],"version-history":[{"count":3,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2937\/revisions"}],"predecessor-version":[{"id":4645,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2937\/revisions\/4645"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=2937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=2937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=2937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}