-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathcreation.js
More file actions
48 lines (42 loc) · 1008 Bytes
/
creation.js
File metadata and controls
48 lines (42 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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');
}
}