mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64190 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: James M Snell <jasnell@gmail.com>
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
const assert = require('assert');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
type: ['int', 'string', 'object', 'arraybuffer'],
|
|
n: [1e4],
|
|
});
|
|
|
|
function main({ n, type }) {
|
|
const data = [];
|
|
|
|
switch (type) {
|
|
case 'int':
|
|
for (let i = 0; i < n; ++i) {
|
|
data.push(i);
|
|
}
|
|
break;
|
|
case 'string':
|
|
for (let i = 0; i < n; ++i) {
|
|
data.push(new Date().toISOString());
|
|
}
|
|
break;
|
|
case 'object':
|
|
for (let i = 0; i < n; ++i) {
|
|
data.push({ ...process.config });
|
|
}
|
|
break;
|
|
case 'arraybuffer':
|
|
for (let i = 0; i < n; ++i) {
|
|
data.push(new ArrayBuffer(10));
|
|
}
|
|
break;
|
|
default:
|
|
throw new Error('Unsupported payload type');
|
|
}
|
|
|
|
const run = type === 'arraybuffer' ? (i) => {
|
|
data[i] = structuredClone(data[i], { transfer: [ data[i] ] });
|
|
} : (i) => {
|
|
data[i] = structuredClone(data[i]);
|
|
};
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i) {
|
|
run(i);
|
|
}
|
|
bench.end(n);
|
|
assert.strictEqual(data.length, n);
|
|
}
|