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
|
|
|
});
|
|
|
|
|
|
|
|
function main(conf) {
|
2017-08-04 13:35:13 +02:00
|
|
|
const FreeList = require('internal/freelist');
|
2017-09-14 03:48:53 +02:00
|
|
|
const n = conf.n;
|
|
|
|
const poolSize = 1000;
|
|
|
|
const list = new FreeList('test', poolSize, Object);
|
2016-01-26 13:13:12 +01:00
|
|
|
var i;
|
|
|
|
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();
|
|
|
|
|
2016-03-02 22:38:23 +01:00
|
|
|
for (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);
|
|
|
|
}
|