• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3
4const 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 ** 13, 2 ** 16],
18  n: [2e4],
19});
20
21function 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};
26    }
27  `);
28  bench.start();
29  testFunction(buffer);
30  bench.end(n);
31}
32