Skip to content

Commit e9ec9ff

Browse files
committed
benchmark: add buffer fill benchmark
PR-URL: #18790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 177b731 commit e9ec9ff

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

benchmark/buffers/buffer-fill.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
4+
const bench = common.createBenchmark(main, {
5+
type: [
6+
'fill(0)',
7+
'fill("")',
8+
'fill(100)',
9+
'fill(400)',
10+
'fill("t")',
11+
'fill("test")',
12+
'fill("t", "utf8")',
13+
'fill("t", 0, "utf8")',
14+
'fill("t", 0)',
15+
'fill(Buffer.alloc(1), 0)'
16+
],
17+
size: [2 ** 8, 2 ** 13, 2 ** 16],
18+
n: [2e4]
19+
});
20+
21+
function main({ n, type, size }) {
22+
const buffer = Buffer.allocUnsafe(size);
23+
const testFunction = new Function('b', `
24+
for (var i = 0; i < ${n}; i++) {
25+
b.${type || 'fill(0)'};
26+
}
27+
`);
28+
bench.start();
29+
testFunction(buffer);
30+
bench.end(n);
31+
}

0 commit comments

Comments
 (0)