0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/benchmark/misc/freelist.js
Joyee Cheung 2826e6324c benchmark: allow benchmarks to specify flags
* Give createBenchmark and the Benchmark constructor
  a third argument for specifying the command line flags
  that this benchmark should be run with.
  The benchmarks are no longer run with --expose-internals
  by default, they will need to explicitly pass the flags.
* Rename options to configs in createBenchmark and the Benchmark
  constructor to match the documentation since they are not optional.
* Comment the properties of a Benchmark object

Also improve the documentation about creating benchmarks

* Add detailed description of the arguments of `createBenchmark`
* Describe the two passes of running the benchmarks
* Suggest what kind of code should go where in the benchmark example

PR-URL: https://github.com/nodejs/node/pull/10448
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2017-01-04 22:45:34 +08:00

41 lines
735 B
JavaScript

'use strict';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
n: [100000]
}, {
flags: ['--expose-internals']
});
function main(conf) {
const FreeList = require('internal/freelist').FreeList;
var n = conf.n;
var poolSize = 1000;
var list = new FreeList('test', poolSize, Object);
var i;
var j;
var used = [];
// First, alloc `poolSize` items
for (j = 0; j < poolSize; j++) {
used.push(list.alloc());
}
bench.start();
for (i = 0; i < n; i++) {
// 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);
}