diff --git a/benchmark/process/next-tick-loop-args.js b/benchmark/process/next-tick-loop-args.js new file mode 100644 index 00000000000000..d163a799aee396 --- /dev/null +++ b/benchmark/process/next-tick-loop-args.js @@ -0,0 +1,37 @@ +'use strict'; +const common = require('../common.js'); +const bench = common.createBenchmark(main, { + n: [1e4, 2e4, 4e4], + loop: [1e2, 2e2], +}); + +function main({ n, loop }) { + bench.start(); + run(); + function run() { + let j = 0; + + function cb() { + j++; + if (j === n) { + loop--; + if (loop === 0) { + bench.end(n); + } else { + run(); + } + } + } + + for (let i = 0; i < n; i++) { + if (i % 4 === 0) + process.nextTick(cb, i, true, 10, 'test'); + else if (i % 3 === 0) + process.nextTick(cb, i, true, 10); + else if (i % 2 === 0) + process.nextTick(cb, i, 20); + else + process.nextTick(cb, i); + } + } +} diff --git a/benchmark/process/next-tick-loop.js b/benchmark/process/next-tick-loop.js new file mode 100644 index 00000000000000..5159910e576be7 --- /dev/null +++ b/benchmark/process/next-tick-loop.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common.js'); +const bench = common.createBenchmark(main, { + n: [1e4, 2e4, 4e4], + loop: [1e2, 2e2], +}); + +function main({ n, loop }) { + bench.start(); + run(); + function run() { + let j = 0; + + function cb() { + j++; + if (j === n) { + loop--; + if (loop === 0) { + bench.end(n); + } else { + run(); + } + } + } + + for (let i = 0; i < n; i++) { + process.nextTick(cb); + } + } +} diff --git a/lib/internal/fixed_queue.js b/lib/internal/fixed_queue.js index f6f3110d8ec5d4..4019d6e6dc46fa 100644 --- a/lib/internal/fixed_queue.js +++ b/lib/internal/fixed_queue.js @@ -111,6 +111,7 @@ module.exports = class FixedQueue { if (tail.isEmpty() && tail.next !== null) { // If there is another queue, it forms the new tail. this.tail = tail.next; + tail.next = null; } return next; }