2023-09-20 03:55:09 +02:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const {
|
|
|
|
Blob,
|
|
|
|
} = require('node:buffer');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
n: [50e3],
|
2023-10-17 08:23:40 +02:00
|
|
|
bytes: [128, 1024, 1024 ** 2],
|
2023-09-20 03:55:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let _cloneResult;
|
|
|
|
|
2023-10-17 08:23:40 +02:00
|
|
|
function main({ n, bytes }) {
|
|
|
|
const buff = Buffer.allocUnsafe(bytes);
|
|
|
|
const blob = new Blob(buff);
|
2023-09-20 03:55:09 +02:00
|
|
|
bench.start();
|
|
|
|
for (let i = 0; i < n; ++i)
|
2023-10-17 08:23:40 +02:00
|
|
|
_cloneResult = structuredClone(blob);
|
2023-09-20 03:55:09 +02:00
|
|
|
bench.end(n);
|
|
|
|
|
|
|
|
// Avoid V8 deadcode (elimination)
|
|
|
|
assert.ok(_cloneResult);
|
|
|
|
}
|