• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common.js');
4
5const bench = common.createBenchmark(main, {
6  n: [100000],
7}, {
8  flags: ['--expose-internals'],
9});
10
11function main({ n }) {
12  let FreeList = require('internal/freelist');
13  if (FreeList.FreeList)
14    FreeList = FreeList.FreeList;
15  const poolSize = 1000;
16  const list = new FreeList('test', poolSize, Object);
17  let j;
18  const used = [];
19
20  // First, alloc `poolSize` items
21  for (j = 0; j < poolSize; j++) {
22    used.push(list.alloc());
23  }
24
25  bench.start();
26
27  for (let i = 0; i < n; i++) {
28    // Return all the items to the pool
29    for (j = 0; j < poolSize; j++) {
30      list.free(used[j]);
31    }
32
33    // Re-alloc from pool
34    for (j = 0; j < poolSize; j++) {
35      list.alloc();
36    }
37  }
38
39  bench.end(n);
40}
41