Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 86fe5a8

Browse filesBrowse files
H4adnodejs-github-bot
authored andcommitted
benchmark: added new benchmarks for blob
PR-URL: #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>
1 parent 328bdac commit 86fe5a8
Copy full SHA for 86fe5a8

File tree

Expand file treeCollapse file tree

4 files changed

+119
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+119
-0
lines changed
Open diff view settings
Collapse file

‎benchmark/blob/clone.js‎

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const {
4+
Blob,
5+
} = require('node:buffer');
6+
const assert = require('assert');
7+
8+
const bench = common.createBenchmark(main, {
9+
n: [50e3],
10+
});
11+
12+
let _cloneResult;
13+
14+
function main({ n }) {
15+
bench.start();
16+
for (let i = 0; i < n; ++i)
17+
_cloneResult = structuredClone(new Blob(['hello']));
18+
bench.end(n);
19+
20+
// Avoid V8 deadcode (elimination)
21+
assert.ok(_cloneResult);
22+
}
Collapse file

‎benchmark/blob/creation.js‎

Copy file name to clipboard
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const {
4+
Blob,
5+
} = require('node:buffer');
6+
const assert = require('assert');
7+
8+
const options = {
9+
flags: ['--expose-internals'],
10+
};
11+
12+
const bench = common.createBenchmark(main, {
13+
n: [50e3],
14+
kind: [
15+
'Blob',
16+
'createBlob',
17+
],
18+
}, options);
19+
20+
let _blob;
21+
let _createBlob;
22+
23+
function main({ n, kind }) {
24+
switch (kind) {
25+
case 'Blob': {
26+
bench.start();
27+
for (let i = 0; i < n; ++i)
28+
_blob = new Blob(['hello']);
29+
bench.end(n);
30+
31+
// Avoid V8 deadcode (elimination)
32+
assert.ok(_blob);
33+
break;
34+
} case 'createBlob': {
35+
const { createBlob } = require('internal/blob');
36+
const reusableBlob = new Blob(['hello']);
37+
bench.start();
38+
for (let i = 0; i < n; ++i)
39+
_createBlob = createBlob(reusableBlob, reusableBlob.size);
40+
bench.end(n);
41+
42+
// Avoid V8 deadcode (elimination)
43+
assert.ok(_createBlob);
44+
break;
45+
} default:
46+
throw new Error('Invalid kind');
47+
}
48+
}
Collapse file

‎benchmark/blob/resolveObjectURL.js‎

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { Blob, resolveObjectURL } = require('node:buffer');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [50e3],
8+
});
9+
10+
let _resolveObjectURL;
11+
12+
function main({ n }) {
13+
const blob = new Blob(['hello']);
14+
const id = URL.createObjectURL(blob);
15+
bench.start();
16+
for (let i = 0; i < n; ++i)
17+
_resolveObjectURL = resolveObjectURL(id);
18+
bench.end(n);
19+
20+
// Avoid V8 deadcode (elimination)
21+
assert.ok(_resolveObjectURL);
22+
}
Collapse file

‎benchmark/blob/slice.js‎

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { Blob } = require('node:buffer');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [50e3],
8+
dataSize: [
9+
5,
10+
30 * 1024,
11+
],
12+
});
13+
14+
let _sliceResult;
15+
16+
function main({ n, dataSize }) {
17+
const data = 'a'.repeat(dataSize);
18+
const reusableBlob = new Blob([data]);
19+
20+
bench.start();
21+
for (let i = 0; i < n; ++i)
22+
_sliceResult = reusableBlob.slice(0, Math.floor(data.length / 2));
23+
bench.end(n);
24+
25+
// Avoid V8 deadcode (elimination)
26+
assert.ok(_sliceResult);
27+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.