mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 21:46:48 +00:00
benchmark: added new benchmarks for blob
PR-URL: https://github.com/nodejs/node/pull/49730 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
This commit is contained in:
parent
328bdac7f0
commit
86fe5a80f3
22
benchmark/blob/clone.js
Normal file
22
benchmark/blob/clone.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common.js');
|
||||||
|
const {
|
||||||
|
Blob,
|
||||||
|
} = require('node:buffer');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const bench = common.createBenchmark(main, {
|
||||||
|
n: [50e3],
|
||||||
|
});
|
||||||
|
|
||||||
|
let _cloneResult;
|
||||||
|
|
||||||
|
function main({ n }) {
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; ++i)
|
||||||
|
_cloneResult = structuredClone(new Blob(['hello']));
|
||||||
|
bench.end(n);
|
||||||
|
|
||||||
|
// Avoid V8 deadcode (elimination)
|
||||||
|
assert.ok(_cloneResult);
|
||||||
|
}
|
48
benchmark/blob/creation.js
Normal file
48
benchmark/blob/creation.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common.js');
|
||||||
|
const {
|
||||||
|
Blob,
|
||||||
|
} = require('node:buffer');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
flags: ['--expose-internals'],
|
||||||
|
};
|
||||||
|
|
||||||
|
const bench = common.createBenchmark(main, {
|
||||||
|
n: [50e3],
|
||||||
|
kind: [
|
||||||
|
'Blob',
|
||||||
|
'createBlob',
|
||||||
|
],
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
let _blob;
|
||||||
|
let _createBlob;
|
||||||
|
|
||||||
|
function main({ n, kind }) {
|
||||||
|
switch (kind) {
|
||||||
|
case 'Blob': {
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; ++i)
|
||||||
|
_blob = new Blob(['hello']);
|
||||||
|
bench.end(n);
|
||||||
|
|
||||||
|
// Avoid V8 deadcode (elimination)
|
||||||
|
assert.ok(_blob);
|
||||||
|
break;
|
||||||
|
} case 'createBlob': {
|
||||||
|
const { createBlob } = require('internal/blob');
|
||||||
|
const reusableBlob = new Blob(['hello']);
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; ++i)
|
||||||
|
_createBlob = createBlob(reusableBlob, reusableBlob.size);
|
||||||
|
bench.end(n);
|
||||||
|
|
||||||
|
// Avoid V8 deadcode (elimination)
|
||||||
|
assert.ok(_createBlob);
|
||||||
|
break;
|
||||||
|
} default:
|
||||||
|
throw new Error('Invalid kind');
|
||||||
|
}
|
||||||
|
}
|
22
benchmark/blob/resolveObjectURL.js
Normal file
22
benchmark/blob/resolveObjectURL.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common.js');
|
||||||
|
const { Blob, resolveObjectURL } = require('node:buffer');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const bench = common.createBenchmark(main, {
|
||||||
|
n: [50e3],
|
||||||
|
});
|
||||||
|
|
||||||
|
let _resolveObjectURL;
|
||||||
|
|
||||||
|
function main({ n }) {
|
||||||
|
const blob = new Blob(['hello']);
|
||||||
|
const id = URL.createObjectURL(blob);
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; ++i)
|
||||||
|
_resolveObjectURL = resolveObjectURL(id);
|
||||||
|
bench.end(n);
|
||||||
|
|
||||||
|
// Avoid V8 deadcode (elimination)
|
||||||
|
assert.ok(_resolveObjectURL);
|
||||||
|
}
|
27
benchmark/blob/slice.js
Normal file
27
benchmark/blob/slice.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common.js');
|
||||||
|
const { Blob } = require('node:buffer');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const bench = common.createBenchmark(main, {
|
||||||
|
n: [50e3],
|
||||||
|
dataSize: [
|
||||||
|
5,
|
||||||
|
30 * 1024,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
let _sliceResult;
|
||||||
|
|
||||||
|
function main({ n, dataSize }) {
|
||||||
|
const data = 'a'.repeat(dataSize);
|
||||||
|
const reusableBlob = new Blob([data]);
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; ++i)
|
||||||
|
_sliceResult = reusableBlob.slice(0, Math.floor(data.length / 2));
|
||||||
|
bench.end(n);
|
||||||
|
|
||||||
|
// Avoid V8 deadcode (elimination)
|
||||||
|
assert.ok(_sliceResult);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user