-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-2-speed.js
127 lines (97 loc) · 2.86 KB
/
test-2-speed.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import {decode, encode} from "../index.js";
const input = "QWERTY1234".repeat(100_000*5);
console.log(`Input: ${input.length} chars string`);
// -----------------------------------
console.log("\n--- AlttiRi/base85 ---");
console.time("total");
console.time("encode");
const encodedAb = new TextEncoder().encode(input);
const encoded1 = encode(encodedAb);
console.timeEnd("encode");
console.time("decode");
const decodedAB = decode(encoded1);
const output1 = new TextDecoder().decode(decodedAB);
console.timeEnd("decode");
console.timeEnd("total");
console.log("input === output1:", input === output1);
/*
Input: 5000000 chars string
--- AlttiRi/base85 ---
encode: 51.036ms
decode: 28.376ms
total: 79.884ms
input === output1: true
--- noseglid/base85 ---
encode: 743.496ms
decode: 80.996ms
total: 825.063ms
input === output2: true
output1 === output2: true
--- Sheep-y/Base85 ---
encode: 70.319ms
decode: 40.662ms
total: 111.481ms
input === output3: true
output1 === output3: true
--- huandu/node-ascii85 ---
encode: 768.081ms
decode: 63.721ms
total: 832.394ms
input === output4: true
output1 === output4: true
*/
// Uncomment and install "base85"
/*
// -----------------------------------
console.log("\n--- noseglid/base85 ---");
// https://github.com/noseglid/base85
import base85 from "base85";
console.time("total");
console.time("encode");
const encoded2 = base85.encode(input).toString();
console.timeEnd("encode");
console.time("decode");
const output2 = base85.decode(encoded2).toString();
console.timeEnd("decode");
console.timeEnd("total");
console.log("input === output2:", input === output2);
console.log("output1 === output2:", output1 === output2);
*/
// Uncomment and copy-paste the code from GitHub
/*
// -----------------------------------
console.log("\n--- Sheep-y/Base85 ---");
// put code here from
// https://github.com/Sheep-y/Base85/blob/master/javascript/base85.js
(function() {})(
...
);
console.time("total");
console.time("encode");
const encoded3 = Base85.Z85Encoder.encode(input);
console.timeEnd("encode");
console.time("decode");
const output3 = Base85.Z85Decoder.decode(encoded3);
console.timeEnd("decode");
console.timeEnd("total");
console.log("input === output3:", input === output3);
console.log("output1 === output3:", output1 === output3);
*/
/*
// Uncomment and install "ascii85"
// -----------------------------------
console.log("\n--- huandu/node-ascii85 ---");
// https://github.com/huandu/node-ascii85
import ascii85 from "ascii85";
let ZeroMQ = ascii85.ZeroMQ;
console.time("total");
console.time("encode");
const encoded3 = ZeroMQ.encode(input).toString();
console.timeEnd("encode");
console.time("decode");
const output4 = ZeroMQ.decode(encoded3).toString();
console.timeEnd("decode");
console.timeEnd("total");
console.log("input === output4:", input === output4);
console.log("output1 === output4:", output1 === output4);
*/