deno.land / x / msgpack_javascript@v3.0.0-beta2 / benchmark / msgpack-benchmark.js

msgpack-benchmark.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* eslint-disable no-console */// based on https://github.com/endel/msgpack-benchmark"use strict";require("ts-node/register");const Benchmark = require("benchmark");const fs = require("fs");const msgpack = require("../src");
const implementations = { "@msgpack/msgpack": { encode: require("..").encode, decode: require("..").decode, }, "msgpack-lite": { encode: require("msgpack-lite").encode, decode: require("msgpack-lite").decode, }, "notepack.io": { encode: require("notepack.io/browser/encode"), decode: require("notepack.io/browser/decode"), },};
// exactly the same as:// https://raw.githubusercontent.com/endel/msgpack-benchmark/master/sample-large.jsonconst sampleFiles = ["./sample-large.json"];
function validate(name, data, encoded) { if (JSON.stringify(data) !== JSON.stringify(implementations[name].decode(encoded))) { throw new Error("Bad implementation: " + name); }}
for (const sampleFile of sampleFiles) { const data = require(sampleFile); const encodeSuite = new Benchmark.Suite(); const decodeSuite = new Benchmark.Suite();
console.log(""); console.log("**" + sampleFile + ":** (" + JSON.stringify(data).length + " bytes in JSON)"); console.log("");
for (const name of Object.keys(implementations)) { implementations[name].toDecode = implementations[name].encode(data); validate(name, data, implementations[name].toDecode); encodeSuite.add("(encode) " + name, () => { implementations[name].encode(data); }); decodeSuite.add("(decode) " + name, () => { implementations[name].decode(implementations[name].toDecode); }); } encodeSuite.on("cycle", (event) => { console.log(String(event.target)); });
console.log("```"); encodeSuite.run(); console.log("```");
console.log("");
decodeSuite.on("cycle", function(event) { console.log(String(event.target)); });
console.log("```"); decodeSuite.run(); console.log("```");}
msgpack_javascript

Version Info

Tagged at
a year ago