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 a27c994

Browse filesBrowse files
anonrigRafaelGSS
authored andcommitted
benchmark: add blob benchmark
PR-URL: #44990 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent c1ca19f commit a27c994
Copy full SHA for a27c994

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

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

‎benchmark/blob/blob.js‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { Blob } = require('buffer');
4+
5+
const bench = common.createBenchmark(main, {
6+
bytes: [128, 1024, 1024 ** 2],
7+
n: [1e6],
8+
operation: ['text', 'arrayBuffer']
9+
});
10+
11+
async function run(n, bytes, operation) {
12+
const buff = Buffer.allocUnsafe(bytes);
13+
const source = new Blob(buff);
14+
bench.start();
15+
for (let i = 0; i < n; i++) {
16+
switch (operation) {
17+
case 'text':
18+
await source.text();
19+
break;
20+
case 'arrayBuffer':
21+
await source.arrayBuffer();
22+
break;
23+
}
24+
}
25+
bench.end(n);
26+
}
27+
28+
function main(conf) {
29+
run(conf.n, conf.bytes, conf.operation).catch(console.log);
30+
}
Collapse file
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const runBenchmark = require('../common/benchmark');
6+
7+
runBenchmark('blob', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 commit comments

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