2016-01-26 13:13:12 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const common = require('../common.js');
|
2016-01-26 13:13:12 +01:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const bench = common.createBenchmark(main, {
|
2016-01-26 13:13:12 +01:00
|
|
|
n: [100000]
|
2016-12-29 13:07:08 +01:00
|
|
|
}, {
|
|
|
|
flags: ['--expose-internals']
|
2016-01-26 13:13:12 +01:00
|
|
|
});
|
|
|
|
|
2017-12-30 03:57:38 +01:00
|
|
|
function main({ n }) {
|
2019-03-30 22:13:50 +01:00
|
|
|
let FreeList = require('internal/freelist');
|
|
|
|
if (FreeList.FreeList)
|
|
|
|
FreeList = FreeList.FreeList;
|
2017-09-14 03:48:53 +02:00
|
|
|
const poolSize = 1000;
|
|
|
|
const list = new FreeList('test', poolSize, Object);
|
2016-01-26 13:13:12 +01:00
|
|
|
var j;
|
2017-09-14 03:48:53 +02:00
|
|
|
const used = [];
|
2016-01-26 13:13:12 +01:00
|
|
|
|
|
|
|
// First, alloc `poolSize` items
|
|
|
|
for (j = 0; j < poolSize; j++) {
|
|
|
|
used.push(list.alloc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
|
2018-01-23 13:19:30 +01:00
|
|
|
for (var i = 0; i < n; i++) {
|
2016-01-26 13:13:12 +01:00
|
|
|
// Return all the items to the pool
|
|
|
|
for (j = 0; j < poolSize; j++) {
|
|
|
|
list.free(used[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re-alloc from pool
|
|
|
|
for (j = 0; j < poolSize; j++) {
|
|
|
|
list.alloc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bench.end(n);
|
|
|
|
}
|