nv-buf-serde 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DIST/dist.js +25 -0
- package/README.md +382 -0
- package/TEST/common.js +435 -0
- package/TEST/hole-tst.js +31 -0
- package/TEST/nd-benchmark.js +17 -0
- package/TEST/r-1bstr.js +33 -0
- package/TEST/r-2bstr.js +33 -0
- package/TEST/r-ab-and-abvw.js +48 -0
- package/TEST/r-bi.js +33 -0
- package/TEST/r-date.js +28 -0
- package/TEST/r-double.js +33 -0
- package/TEST/r-int-not-smi.js +28 -0
- package/TEST/r-mp-st-circular.js +105 -0
- package/TEST/r-odd-ball.js +33 -0
- package/TEST/r-packed-double.js +38 -0
- package/TEST/r-packed-smi.js +35 -0
- package/TEST/r-packed-with-attr.js +40 -0
- package/TEST/r-prim-wrap.js +35 -0
- package/TEST/r-rgx.js +28 -0
- package/TEST/r-smi.js +28 -0
- package/TEST/read-bi-contents.js +20 -0
- package/TEST/run.js +43 -0
- package/TEST/run.sh +29 -0
- package/TEST/serde-benchmark.js +17 -0
- package/TEST/tst.json +114 -0
- package/TEST/tst.v8ser +0 -0
- package/TEST/w-1bstr.js +34 -0
- package/TEST/w-2bstr.js +34 -0
- package/TEST/w-ab-and-abvw.js +60 -0
- package/TEST/w-bi.js +33 -0
- package/TEST/w-date.js +33 -0
- package/TEST/w-double.js +35 -0
- package/TEST/w-int-not-smi.js +37 -0
- package/TEST/w-mp-st-circular.js +60 -0
- package/TEST/w-odd-ball.js +43 -0
- package/TEST/w-packed-double.js +40 -0
- package/TEST/w-packed-smi.js +38 -0
- package/TEST/w-packed-with-attr.js +41 -0
- package/TEST/w-prim-wrap.js +41 -0
- package/TEST/w-rgx.js +33 -0
- package/TEST/w-smi.js +36 -0
- package/build.sh +1 -0
- package/const.js +181 -0
- package/ctx.js +89 -0
- package/fixed-cfg.js +6 -0
- package/index.js +27 -0
- package/misc.js +112 -0
- package/package.json +22 -0
- package/r.js +646 -0
- package/restrict.js +48 -0
- package/w.js +510 -0
- package/zero-nid.js +21 -0
package/TEST/common.js
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
const child_process = require('child_process');
|
|
2
|
+
//const http_benchmarkers = require('./_http-benchmarkers.js');
|
|
3
|
+
|
|
4
|
+
function allow() {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class Benchmark {
|
|
9
|
+
constructor(fn, configs, options = {}) {
|
|
10
|
+
// Used to make sure a benchmark only start a timer once
|
|
11
|
+
this._started = false;
|
|
12
|
+
|
|
13
|
+
// Indicate that the benchmark ended
|
|
14
|
+
this._ended = false;
|
|
15
|
+
|
|
16
|
+
// Holds process.hrtime value
|
|
17
|
+
this._time = 0n;
|
|
18
|
+
|
|
19
|
+
// Use the file name as the name of the benchmark
|
|
20
|
+
this.name = require.main.filename.slice(__dirname.length + 1);
|
|
21
|
+
|
|
22
|
+
// Execution arguments i.e. flags used to run the jobs
|
|
23
|
+
this.flags = process.env.NODE_BENCHMARK_FLAGS ?
|
|
24
|
+
process.env.NODE_BENCHMARK_FLAGS.split(/\s+/) :
|
|
25
|
+
[];
|
|
26
|
+
|
|
27
|
+
// Parse job-specific configuration from the command line arguments
|
|
28
|
+
const argv = process.argv.slice(2);
|
|
29
|
+
const parsed_args = this._parseArgs(argv, configs, options);
|
|
30
|
+
this.options = parsed_args.cli;
|
|
31
|
+
this.extra_options = parsed_args.extra;
|
|
32
|
+
if (options.flags) {
|
|
33
|
+
this.flags = this.flags.concat(options.flags);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof options.combinationFilter === 'function')
|
|
37
|
+
this.combinationFilter = options.combinationFilter;
|
|
38
|
+
else
|
|
39
|
+
this.combinationFilter = allow;
|
|
40
|
+
|
|
41
|
+
// The configuration list as a queue of jobs
|
|
42
|
+
this.queue = this._queue(this.options);
|
|
43
|
+
|
|
44
|
+
if (this.queue.length === 0)
|
|
45
|
+
return;
|
|
46
|
+
|
|
47
|
+
// The configuration of the current job, head of the queue
|
|
48
|
+
this.config = this.queue[0];
|
|
49
|
+
|
|
50
|
+
process.nextTick(() => {
|
|
51
|
+
if (process.env.NODE_RUN_BENCHMARK_FN !== undefined) {
|
|
52
|
+
fn(this.config);
|
|
53
|
+
} else {
|
|
54
|
+
// _run will use fork() to create a new process for each configuration
|
|
55
|
+
// combination.
|
|
56
|
+
this._run();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_parseArgs(argv, configs, options) {
|
|
62
|
+
const cliOptions = {};
|
|
63
|
+
|
|
64
|
+
// Check for the test mode first.
|
|
65
|
+
const testIndex = argv.indexOf('--test');
|
|
66
|
+
if (testIndex !== -1) {
|
|
67
|
+
for (const [key, rawValue] of Object.entries(configs)) {
|
|
68
|
+
let value = Array.isArray(rawValue) ? rawValue[0] : rawValue;
|
|
69
|
+
// Set numbers to one by default to reduce the runtime.
|
|
70
|
+
if (typeof value === 'number') {
|
|
71
|
+
if (key === 'dur' || key === 'duration') {
|
|
72
|
+
value = 0.05;
|
|
73
|
+
} else if (value > 1) {
|
|
74
|
+
value = 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
cliOptions[key] = [value];
|
|
78
|
+
}
|
|
79
|
+
// Override specific test options.
|
|
80
|
+
if (options.test) {
|
|
81
|
+
for (const [key, value] of Object.entries(options.test)) {
|
|
82
|
+
cliOptions[key] = Array.isArray(value) ? value : [value];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
argv.splice(testIndex, 1);
|
|
86
|
+
} else {
|
|
87
|
+
// Accept single values instead of arrays.
|
|
88
|
+
for (const [key, value] of Object.entries(configs)) {
|
|
89
|
+
if (!Array.isArray(value))
|
|
90
|
+
configs[key] = [value];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const extraOptions = {};
|
|
95
|
+
const validArgRE = /^(.+?)=([\s\S]*)$/;
|
|
96
|
+
// Parse configuration arguments
|
|
97
|
+
for (const arg of argv) {
|
|
98
|
+
const match = arg.match(validArgRE);
|
|
99
|
+
if (!match) {
|
|
100
|
+
console.error(`bad argument: ${arg}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
const [, key, value] = match;
|
|
104
|
+
if (configs[key] !== undefined) {
|
|
105
|
+
if (!cliOptions[key])
|
|
106
|
+
cliOptions[key] = [];
|
|
107
|
+
cliOptions[key].push(
|
|
108
|
+
// Infer the type from the config object and parse accordingly
|
|
109
|
+
typeof configs[key][0] === 'number' ? +value : value,
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
extraOptions[key] = value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { cli: { ...configs, ...cliOptions }, extra: extraOptions };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
_queue(options) {
|
|
119
|
+
const queue = [];
|
|
120
|
+
const keys = Object.keys(options);
|
|
121
|
+
const { combinationFilter } = this;
|
|
122
|
+
|
|
123
|
+
// Perform a depth-first walk through all options to generate a
|
|
124
|
+
// configuration list that contains all combinations.
|
|
125
|
+
function recursive(keyIndex, prevConfig) {
|
|
126
|
+
const key = keys[keyIndex];
|
|
127
|
+
const values = options[key];
|
|
128
|
+
|
|
129
|
+
for (const value of values) {
|
|
130
|
+
if (typeof value !== 'number' && typeof value !== 'string') {
|
|
131
|
+
throw new TypeError(
|
|
132
|
+
`configuration "${key}" had type ${typeof value}`);
|
|
133
|
+
}
|
|
134
|
+
if (typeof value !== typeof values[0]) {
|
|
135
|
+
// This is a requirement for being able to consistently and
|
|
136
|
+
// predictably parse CLI provided configuration values.
|
|
137
|
+
throw new TypeError(`configuration "${key}" has mixed types`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const currConfig = { [key]: value, ...prevConfig };
|
|
141
|
+
|
|
142
|
+
if (keyIndex + 1 < keys.length) {
|
|
143
|
+
recursive(keyIndex + 1, currConfig);
|
|
144
|
+
} else {
|
|
145
|
+
// Check if we should allow the current combination
|
|
146
|
+
const allowed = combinationFilter({ ...currConfig });
|
|
147
|
+
if (typeof allowed !== 'boolean') {
|
|
148
|
+
throw new TypeError(
|
|
149
|
+
'Combination filter must always return a boolean',
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (allowed)
|
|
153
|
+
queue.push(currConfig);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (keys.length > 0) {
|
|
159
|
+
recursive(0, {});
|
|
160
|
+
} else {
|
|
161
|
+
queue.push({});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return queue;
|
|
165
|
+
}
|
|
166
|
+
/*
|
|
167
|
+
http(options, cb) {
|
|
168
|
+
const http_options = { ...options };
|
|
169
|
+
http_options.benchmarker = http_options.benchmarker ||
|
|
170
|
+
this.config.benchmarker ||
|
|
171
|
+
this.extra_options.benchmarker ||
|
|
172
|
+
http_benchmarkers.default_http_benchmarker;
|
|
173
|
+
http_benchmarkers.run(
|
|
174
|
+
http_options, (error, code, used_benchmarker, result, elapsed) => {
|
|
175
|
+
if (cb) {
|
|
176
|
+
cb(code);
|
|
177
|
+
}
|
|
178
|
+
if (error) {
|
|
179
|
+
console.error(error);
|
|
180
|
+
process.exit(code || 1);
|
|
181
|
+
}
|
|
182
|
+
this.config.benchmarker = used_benchmarker;
|
|
183
|
+
this.report(result, elapsed);
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
*/
|
|
188
|
+
_run() {
|
|
189
|
+
// If forked, report to the parent.
|
|
190
|
+
if (process.send) {
|
|
191
|
+
process.send({
|
|
192
|
+
type: 'config',
|
|
193
|
+
name: this.name,
|
|
194
|
+
queueLength: this.queue.length,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const recursive = (queueIndex) => {
|
|
199
|
+
const config = this.queue[queueIndex];
|
|
200
|
+
|
|
201
|
+
// Set NODE_RUN_BENCHMARK_FN to indicate that the child shouldn't
|
|
202
|
+
// construct a configuration queue, but just execute the benchmark
|
|
203
|
+
// function.
|
|
204
|
+
const childEnv = { ...process.env };
|
|
205
|
+
childEnv.NODE_RUN_BENCHMARK_FN = '';
|
|
206
|
+
|
|
207
|
+
// Create configuration arguments
|
|
208
|
+
const childArgs = [];
|
|
209
|
+
for (const [key, value] of Object.entries(config)) {
|
|
210
|
+
childArgs.push(`${key}=${value}`);
|
|
211
|
+
}
|
|
212
|
+
for (const [key, value] of Object.entries(this.extra_options)) {
|
|
213
|
+
childArgs.push(`${key}=${value}`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const child = child_process.fork(require.main.filename, childArgs, {
|
|
217
|
+
env: childEnv,
|
|
218
|
+
execArgv: this.flags.concat(process.execArgv),
|
|
219
|
+
});
|
|
220
|
+
child.on('message', sendResult);
|
|
221
|
+
child.on('close', (code) => {
|
|
222
|
+
if (code) {
|
|
223
|
+
process.exit(code);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (queueIndex + 1 < this.queue.length) {
|
|
227
|
+
recursive(queueIndex + 1);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
recursive(0);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
start() {
|
|
236
|
+
if (this._started) {
|
|
237
|
+
throw new Error('Called start more than once in a single benchmark');
|
|
238
|
+
}
|
|
239
|
+
this._started = true;
|
|
240
|
+
this._time = process.hrtime.bigint();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
end(operations) {
|
|
244
|
+
// Get elapsed time now and do error checking later for accuracy.
|
|
245
|
+
const time = process.hrtime.bigint();
|
|
246
|
+
|
|
247
|
+
if (!this._started) {
|
|
248
|
+
throw new Error('called end without start');
|
|
249
|
+
}
|
|
250
|
+
if (this._ended) {
|
|
251
|
+
throw new Error('called end multiple times');
|
|
252
|
+
}
|
|
253
|
+
if (typeof operations !== 'number') {
|
|
254
|
+
throw new Error('called end() without specifying operation count');
|
|
255
|
+
}
|
|
256
|
+
if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED && operations <= 0) {
|
|
257
|
+
throw new Error('called end() with operation count <= 0');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
this._ended = true;
|
|
261
|
+
|
|
262
|
+
if (time === this._time) {
|
|
263
|
+
if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED)
|
|
264
|
+
throw new Error('insufficient clock precision for short benchmark');
|
|
265
|
+
// Avoid dividing by zero
|
|
266
|
+
this.report(operations && Number.MAX_VALUE, 0n);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const elapsed = time - this._time;
|
|
271
|
+
const rate = operations / (Number(elapsed) / 1e9);
|
|
272
|
+
console.log("operations", operations,elapsed ,operations / Number(elapsed))
|
|
273
|
+
this.report(rate, elapsed);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
report(rate, elapsed) {
|
|
277
|
+
sendResult({
|
|
278
|
+
name: this.name,
|
|
279
|
+
conf: this.config,
|
|
280
|
+
rate,
|
|
281
|
+
time: nanoSecondsToString(elapsed),
|
|
282
|
+
type: 'report',
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function nanoSecondsToString(bigint) {
|
|
288
|
+
const str = bigint.toString();
|
|
289
|
+
const decimalPointIndex = str.length - 9;
|
|
290
|
+
if (decimalPointIndex <= 0) {
|
|
291
|
+
return `0.${'0'.repeat(-decimalPointIndex)}${str}`;
|
|
292
|
+
}
|
|
293
|
+
return `${str.slice(0, decimalPointIndex)}.${str.slice(decimalPointIndex)}`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function formatResult(data) {
|
|
297
|
+
// Construct configuration string, " A=a, B=b, ..."
|
|
298
|
+
let conf = '';
|
|
299
|
+
for (const key of Object.keys(data.conf)) {
|
|
300
|
+
conf += ` ${key}=${JSON.stringify(data.conf[key])}`;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let rate = data.rate.toString().split('.');
|
|
304
|
+
rate[0] = rate[0].replace(/(\d)(?=(?:\d\d\d)+(?!\d))/g, '$1,');
|
|
305
|
+
rate = (rate[1] ? rate.join('.') : rate[0]);
|
|
306
|
+
return `${data.name}${conf}: ${rate}\n`;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function sendResult(data) {
|
|
310
|
+
if (process.send) {
|
|
311
|
+
// If forked, report by process send
|
|
312
|
+
process.send(data, () => {
|
|
313
|
+
if (process.env.NODE_RUN_BENCHMARK_FN !== undefined) {
|
|
314
|
+
// If, for any reason, the process is unable to self close within
|
|
315
|
+
// a second after completing, forcefully close it.
|
|
316
|
+
require('timers').setTimeout(() => {
|
|
317
|
+
process.exit(0);
|
|
318
|
+
}, 5000).unref();
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
} else {
|
|
322
|
+
// Otherwise report by stdout
|
|
323
|
+
process.stdout.write(formatResult(data));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const urls = {
|
|
328
|
+
long: 'http://nodejs.org:89/docs/latest/api/foo/bar/qua/13949281/0f28b/' +
|
|
329
|
+
'/5d49/b3020/url.html#test?payload1=true&payload2=false&test=1' +
|
|
330
|
+
'&benchmark=3&foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
|
|
331
|
+
'key=f5c65e1e98fe07e648249ad41e1cfdb0',
|
|
332
|
+
short: 'https://nodejs.org/en/blog/',
|
|
333
|
+
idn: 'http://你好你好.在线',
|
|
334
|
+
auth: 'https://user:pass@example.com/path?search=1',
|
|
335
|
+
file: 'file:///foo/bar/test/node.js',
|
|
336
|
+
ws: 'ws://localhost:9229/f46db715-70df-43ad-a359-7f9949f39868',
|
|
337
|
+
javascript: 'javascript:alert("node is awesome");',
|
|
338
|
+
percent: 'https://%E4%BD%A0/foo',
|
|
339
|
+
dot: 'https://example.org/./a/../b/./c',
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const searchParams = {
|
|
343
|
+
noencode: 'foo=bar&baz=quux&xyzzy=thud',
|
|
344
|
+
multicharsep: 'foo=bar&&&&&&&&&&baz=quux&&&&&&&&&&xyzzy=thud',
|
|
345
|
+
encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud',
|
|
346
|
+
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
|
|
347
|
+
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64',
|
|
348
|
+
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz',
|
|
349
|
+
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' +
|
|
350
|
+
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz',
|
|
351
|
+
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z',
|
|
352
|
+
manyblankpairs: '&&&&&&&&&&&&&&&&&&&&&&&&',
|
|
353
|
+
altspaces: 'foo+bar=baz+quux&xyzzy+thud=quuy+quuz&abc=def+ghi',
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
function getUrlData(withBase) {
|
|
357
|
+
const data = require('../test/fixtures/wpt/url/resources/urltestdata.json');
|
|
358
|
+
const result = [];
|
|
359
|
+
for (const item of data) {
|
|
360
|
+
if (item.failure || !item.input) continue;
|
|
361
|
+
if (withBase) {
|
|
362
|
+
// item.base might be null. It should be converted into `undefined`.
|
|
363
|
+
result.push([item.input, item.base ?? undefined]);
|
|
364
|
+
} else if (item.base !== null) {
|
|
365
|
+
result.push(item.base);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Generate an array of data for URL benchmarks to use.
|
|
373
|
+
* The size of the resulting data set is the original data size * 2 ** `e`.
|
|
374
|
+
* The 'wpt' type contains about 400 data points when `withBase` is true,
|
|
375
|
+
* and 200 data points when `withBase` is false.
|
|
376
|
+
* Other types contain 200 data points with or without base.
|
|
377
|
+
* @param {string} type Type of the data, 'wpt' or a key of `urls`
|
|
378
|
+
* @param {number} e The repetition of the data, as exponent of 2
|
|
379
|
+
* @param {boolean} withBase Whether to include a base URL
|
|
380
|
+
* @param {boolean} asUrl Whether to return the results as URL objects
|
|
381
|
+
* @return {string[] | string[][] | URL[]}
|
|
382
|
+
*/
|
|
383
|
+
function bakeUrlData(type, e = 0, withBase = false, asUrl = false) {
|
|
384
|
+
let result = [];
|
|
385
|
+
if (type === 'wpt') {
|
|
386
|
+
result = getUrlData(withBase);
|
|
387
|
+
} else if (urls[type]) {
|
|
388
|
+
const input = urls[type];
|
|
389
|
+
const item = withBase ? [input, 'about:blank'] : input;
|
|
390
|
+
// Roughly the size of WPT URL test data
|
|
391
|
+
result = new Array(200).fill(item);
|
|
392
|
+
} else {
|
|
393
|
+
throw new Error(`Unknown url data type ${type}`);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (typeof e !== 'number') {
|
|
397
|
+
throw new Error(`e must be a number, received ${e}`);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
for (let i = 0; i < e; ++i) {
|
|
401
|
+
result = result.concat(result);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (asUrl) {
|
|
405
|
+
if (withBase) {
|
|
406
|
+
result = result.map(([input, base]) => new URL(input, base));
|
|
407
|
+
} else {
|
|
408
|
+
result = result.map((input) => new URL(input));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
module.exports = {
|
|
415
|
+
Benchmark,
|
|
416
|
+
//PORT: http_benchmarkers.PORT,
|
|
417
|
+
bakeUrlData,
|
|
418
|
+
binding(bindingName) {
|
|
419
|
+
try {
|
|
420
|
+
const { internalBinding } = require('internal/test/binding');
|
|
421
|
+
|
|
422
|
+
return internalBinding(bindingName);
|
|
423
|
+
} catch {
|
|
424
|
+
return process.binding(bindingName);
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
buildType: process.features.debug ? 'Debug' : 'Release',
|
|
428
|
+
createBenchmark(fn, configs, options) {
|
|
429
|
+
return new Benchmark(fn, configs, options);
|
|
430
|
+
},
|
|
431
|
+
sendResult,
|
|
432
|
+
searchParams,
|
|
433
|
+
urlDataTypes: Object.keys(urls).concat(['wpt']),
|
|
434
|
+
urls,
|
|
435
|
+
};
|
package/TEST/hole-tst.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
//node --allow-natives-syntax
|
|
3
|
+
var buf = fs.readFileSync("tst.v8ser");
|
|
4
|
+
var sparse = v8.deserialize(buf);
|
|
5
|
+
var dense = require("./tst.json");
|
|
6
|
+
assert.deepStrictEqual(sparse,dense);
|
|
7
|
+
|
|
8
|
+
var dupe = JSON.parse(JSON.stringify(sparse));
|
|
9
|
+
%DebugPrint(dupe) // PACKED
|
|
10
|
+
var dupe = structuredClone(sparse);
|
|
11
|
+
%DebugPrint(dupe) // HOLE
|
|
12
|
+
var f0 = (o)=>JSON.parse(JSON.stringify(o))
|
|
13
|
+
|
|
14
|
+
var jdcp = (j) => {
|
|
15
|
+
if(Array.isArray(j)) {
|
|
16
|
+
let a = [];
|
|
17
|
+
for(let i=0;i<j.length;++i) {a.push(jdcp(j[i]))}
|
|
18
|
+
return(a)
|
|
19
|
+
} else if(j===null) {
|
|
20
|
+
return(null)
|
|
21
|
+
} else if(j instanceof Object) {
|
|
22
|
+
let d = {}
|
|
23
|
+
for(let k in j) {d[k] = jdcp(j[k]) }
|
|
24
|
+
return(d)
|
|
25
|
+
} else {
|
|
26
|
+
return(j)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var dupe = jdcp(sparse);
|
|
31
|
+
%DebugPrint(dupe) // PACKED
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const common = require('./common.js');
|
|
2
|
+
const v8 = require('v8');
|
|
3
|
+
|
|
4
|
+
const bench = common.createBenchmark(main, {
|
|
5
|
+
len: [1,2,4,8],
|
|
6
|
+
n: [1000000],
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
function main({ n, len }) {
|
|
10
|
+
const typedArray = new BigUint64Array(len);
|
|
11
|
+
bench.start();
|
|
12
|
+
for (let i = 0; i < n; i++) v8.serialize({ a: 1, b: typedArray });
|
|
13
|
+
bench.end(n);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
package/TEST/r-1bstr.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const {deepStrictEqual} = require("assert");
|
|
2
|
+
const {sync} = require("nv-facutil-simple-test");
|
|
3
|
+
const v8 = require("v8");
|
|
4
|
+
|
|
5
|
+
const {decd} = require("../r");
|
|
6
|
+
|
|
7
|
+
const ENCD_UN = 0X5F;
|
|
8
|
+
const ENCD_NU = 0X30;
|
|
9
|
+
|
|
10
|
+
const to_ab = (buf) => buf.buffer.slice(buf.byteOffset,buf.byteOffset+buf.byteLength);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var bis = ["a","01","abc","abcdefghijklmnopqrstuvwxyz"]
|
|
14
|
+
var bufs = bis.map(r=>v8.serialize(r));
|
|
15
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
16
|
+
|
|
17
|
+
var f0 = (buf)=> v8.deserialize(buf);
|
|
18
|
+
var f1 = (ab)=> decd(ab);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
for(let i=0;i<bis.length;++i) {deepStrictEqual(f1(abs[i]),bis[i])}
|
|
22
|
+
|
|
23
|
+
console.log("OK")
|
|
24
|
+
for(let i = -50000n;i<0n;++i) {bis.push("a","01","abc","abcdefghijklmnopqrstuvwxyz")}
|
|
25
|
+
for(let i = 1n;i<50000n;++i) {bis.push("a","01","abc","abcdefghijklmnopqrstuvwxyz")}
|
|
26
|
+
var bufs = bis.map(r=>v8.serialize(r));
|
|
27
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var ff0 = ()=>bufs.forEach(buf=>f0(buf));
|
|
31
|
+
var ff1 = ()=>abs.forEach(ab=>f1(ab));
|
|
32
|
+
console.log(sync(1,ff0));
|
|
33
|
+
console.log(sync(1,ff1));
|
package/TEST/r-2bstr.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const {deepStrictEqual} = require("assert");
|
|
2
|
+
const {sync} = require("nv-facutil-simple-test");
|
|
3
|
+
const v8 = require("v8");
|
|
4
|
+
|
|
5
|
+
const {decd} = require("../r");
|
|
6
|
+
|
|
7
|
+
const ENCD_UN = 0X5F;
|
|
8
|
+
const ENCD_NU = 0X30;
|
|
9
|
+
|
|
10
|
+
const to_ab = (buf) => buf.buffer.slice(buf.byteOffset,buf.byteOffset+buf.byteLength);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var bis = ["aÿ我𝑒"]
|
|
14
|
+
var bufs = bis.map(r=>v8.serialize(r));
|
|
15
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
16
|
+
|
|
17
|
+
var f0 = (buf)=> v8.deserialize(buf);
|
|
18
|
+
var f1 = (ab)=> decd(ab);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
for(let i=0;i<bis.length;++i) {deepStrictEqual(f1(abs[i]),bis[i])}
|
|
22
|
+
|
|
23
|
+
console.log("OK")
|
|
24
|
+
for(let i = -50000n;i<0n;++i) {bis.push("aÿ我𝑒".repeat(64))}
|
|
25
|
+
for(let i = 1n;i<50000n;++i) {bis.push("aÿ我𝑒".repeat(64))}
|
|
26
|
+
var bufs = bis.map(r=>v8.serialize(r));
|
|
27
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var ff0 = ()=>bufs.forEach(buf=>f0(buf));
|
|
31
|
+
var ff1 = ()=>abs.forEach(ab=>f1(ab));
|
|
32
|
+
console.log(sync(1,ff0));
|
|
33
|
+
console.log(sync(1,ff1));
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const {deepStrictEqual} = require("assert");
|
|
2
|
+
const {sync} = require("nv-facutil-simple-test");
|
|
3
|
+
const v8 = require("v8");
|
|
4
|
+
|
|
5
|
+
const {decd} = require("../r");
|
|
6
|
+
|
|
7
|
+
const ENCD_UN = 0X5F;
|
|
8
|
+
const ENCD_NU = 0X30;
|
|
9
|
+
|
|
10
|
+
const to_ab = (buf) => buf.buffer.slice(buf.byteOffset,buf.byteOffset+buf.byteLength);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var u8a = new Uint8Array([200,201,202])
|
|
14
|
+
var u8ca = new Uint8ClampedArray([1,2,3,4,5,6,7,8]);
|
|
15
|
+
var i8a = new Int8Array([100,-50,255]);
|
|
16
|
+
var u16a = new Uint16Array([65533,65534,65535])
|
|
17
|
+
var i16a = new Int16Array([100,200,300])
|
|
18
|
+
var u32a = new Uint32Array([2**31,2**32-1])
|
|
19
|
+
var i32a = new Int32Array([2**29,2**30])
|
|
20
|
+
var f32a = new Float32Array([1.1,2.2,3.3])
|
|
21
|
+
var f64a = new Float32Array([-(2**52),2**53-1.1])
|
|
22
|
+
var bu64a = new BigUint64Array([2n**63n,2n**64n-1n])
|
|
23
|
+
var bi64a = new BigInt64Array([2n**63n,2n**62n])
|
|
24
|
+
|
|
25
|
+
var ab = new ArrayBuffer(4)
|
|
26
|
+
var dv = new DataView(ab)
|
|
27
|
+
dv.setUint8(0,1)
|
|
28
|
+
dv.setUint8(0,2)
|
|
29
|
+
dv.setUint8(0,3)
|
|
30
|
+
dv.setUint8(0,4)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
var abvws = [u8a,u8ca,i8a,u16a,i16a,u32a,i32a,f32a,f64a,dv,ab,bi64a,bu64a,/*sab*/]
|
|
34
|
+
var bufs = abvws.map(r=>v8.serialize(r));
|
|
35
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
36
|
+
|
|
37
|
+
var f0 = (buf)=> v8.deserialize(buf);
|
|
38
|
+
var f1 = (ab)=> decd(ab);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
for(let i=0;i<abvws.length;++i) {deepStrictEqual(f1(abs[i]),abvws[i])}
|
|
42
|
+
|
|
43
|
+
console.log("OK")
|
|
44
|
+
|
|
45
|
+
var ff0 = ()=>bufs.forEach(buf=>f0(buf));
|
|
46
|
+
var ff1 = ()=>abs.forEach(ab=>f1(ab));
|
|
47
|
+
console.log(sync(1000000,ff0));
|
|
48
|
+
console.log(sync(1000000,ff1));
|
package/TEST/r-bi.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const {deepStrictEqual} = require("assert");
|
|
2
|
+
const {sync} = require("nv-facutil-simple-test");
|
|
3
|
+
const v8 = require("v8");
|
|
4
|
+
|
|
5
|
+
const {decd} = require("../r");
|
|
6
|
+
|
|
7
|
+
const ENCD_UN = 0X5F;
|
|
8
|
+
const ENCD_NU = 0X30;
|
|
9
|
+
|
|
10
|
+
const to_ab = (buf) => buf.buffer.slice(buf.byteOffset,buf.byteOffset+buf.byteLength);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var bis = [12345678901234567890234567890n,-0n,0n,2n**64n]
|
|
14
|
+
var bufs = bis.map(r=>v8.serialize(r));
|
|
15
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
16
|
+
|
|
17
|
+
var f0 = (buf)=> v8.deserialize(buf);
|
|
18
|
+
var f1 = (ab)=> decd(ab);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
for(let i=0;i<bis.length;++i) {deepStrictEqual(f1(abs[i]),bis[i])}
|
|
22
|
+
|
|
23
|
+
console.log("OK")
|
|
24
|
+
for(let i = -500000n;i<0n;++i) {bis.push(i**2n)}
|
|
25
|
+
for(let i = 1n;i<500000n;++i) {bis.push(i**2n)}
|
|
26
|
+
var bufs = bis.map(r=>v8.serialize(r));
|
|
27
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var ff0 = ()=>bufs.forEach(buf=>f0(buf));
|
|
31
|
+
var ff1 = ()=>abs.forEach(ab=>f1(ab));
|
|
32
|
+
console.log(sync(1,ff0));
|
|
33
|
+
console.log(sync(1,ff1));
|
package/TEST/r-date.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const {deepStrictEqual} = require("assert");
|
|
2
|
+
const {sync} = require("nv-facutil-simple-test");
|
|
3
|
+
const v8 = require("v8");
|
|
4
|
+
|
|
5
|
+
const {decd} = require("../r");
|
|
6
|
+
|
|
7
|
+
const ENCD_UN = 0X5F;
|
|
8
|
+
const ENCD_NU = 0X30;
|
|
9
|
+
|
|
10
|
+
const to_ab = (buf) => buf.buffer.slice(buf.byteOffset,buf.byteOffset+buf.byteLength);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var dts = [new Date,new Date("2023-05-28T16:10:07.133Z")]
|
|
14
|
+
var bufs = dts.map(r=>v8.serialize(r));
|
|
15
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
16
|
+
|
|
17
|
+
var f0 = (buf)=> v8.deserialize(buf);
|
|
18
|
+
var f1 = (ab)=> decd(ab);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
for(let i=0;i<dts.length;++i) {deepStrictEqual(f1(abs[i]),dts[i])}
|
|
22
|
+
|
|
23
|
+
console.log("OK")
|
|
24
|
+
|
|
25
|
+
var ff0 = ()=>bufs.forEach(buf=>f0(buf));
|
|
26
|
+
var ff1 = ()=>abs.forEach(ab=>f1(ab));
|
|
27
|
+
console.log(sync(1000000,ff0));
|
|
28
|
+
console.log(sync(1000000,ff1));
|
package/TEST/r-double.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const {deepStrictEqual} = require("assert");
|
|
2
|
+
const {sync} = require("nv-facutil-simple-test");
|
|
3
|
+
const v8 = require("v8");
|
|
4
|
+
|
|
5
|
+
const {decd} = require("../r");
|
|
6
|
+
|
|
7
|
+
const ENCD_UN = 0X5F;
|
|
8
|
+
const ENCD_NU = 0X30;
|
|
9
|
+
|
|
10
|
+
const to_ab = (buf) => buf.buffer.slice(buf.byteOffset,buf.byteOffset+buf.byteLength);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var nums = [-(2**31)-1, -1.1,-0,1.1, 2**31]
|
|
14
|
+
var bufs = nums.map(r=>v8.serialize(r));
|
|
15
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
16
|
+
|
|
17
|
+
var f0 = (buf)=> v8.deserialize(buf);
|
|
18
|
+
var f1 = (ab)=> decd(ab);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
for(let i=0;i<nums.length;++i) {deepStrictEqual(f1(abs[i]),nums[i])}
|
|
22
|
+
|
|
23
|
+
console.log("OK")
|
|
24
|
+
for(let i = -500000;i<0;++i) {nums.push(Math.random()+i)}
|
|
25
|
+
for(let i = 1;i<500000;++i) {nums.push(Math.random()+i)}
|
|
26
|
+
var bufs = nums.map(r=>v8.serialize(r));
|
|
27
|
+
var abs = bufs.map(buf=>to_ab(buf));
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var ff0 = ()=>bufs.forEach(buf=>f0(buf));
|
|
31
|
+
var ff1 = ()=>abs.forEach(ab=>f1(ab));
|
|
32
|
+
console.log(sync(1,ff0));
|
|
33
|
+
console.log(sync(1,ff1));
|