Skip to content

Commit

Permalink
benchmark: fix next-tick-depth
Browse files Browse the repository at this point in the history
A recent change made these benchmarks fail by always finishing
with 0 iterations. Restore a counter variable.

PR-URL: #20461
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
apapirovski committed May 3, 2018
1 parent 24a5ac7 commit a957f24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
33 changes: 17 additions & 16 deletions benchmark/process/next-tick-depth-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,53 @@ const bench = common.createBenchmark(main, {
process.maxTickDepth = Infinity;

function main({ n }) {
let counter = n;
function cb4(arg1, arg2, arg3, arg4) {
if (--n) {
if (n % 4 === 0)
if (--counter) {
if (counter % 4 === 0)
process.nextTick(cb4, 3.14, 1024, true, false);
else if (n % 3 === 0)
else if (counter % 3 === 0)
process.nextTick(cb3, 512, true, null);
else if (n % 2 === 0)
else if (counter % 2 === 0)
process.nextTick(cb2, false, 5.1);
else
process.nextTick(cb1, 0);
} else
bench.end(n);
}
function cb3(arg1, arg2, arg3) {
if (--n) {
if (n % 4 === 0)
if (--counter) {
if (counter % 4 === 0)
process.nextTick(cb4, 3.14, 1024, true, false);
else if (n % 3 === 0)
else if (counter % 3 === 0)
process.nextTick(cb3, 512, true, null);
else if (n % 2 === 0)
else if (counter % 2 === 0)
process.nextTick(cb2, false, 5.1);
else
process.nextTick(cb1, 0);
} else
bench.end(n);
}
function cb2(arg1, arg2) {
if (--n) {
if (n % 4 === 0)
if (--counter) {
if (counter % 4 === 0)
process.nextTick(cb4, 3.14, 1024, true, false);
else if (n % 3 === 0)
else if (counter % 3 === 0)
process.nextTick(cb3, 512, true, null);
else if (n % 2 === 0)
else if (counter % 2 === 0)
process.nextTick(cb2, false, 5.1);
else
process.nextTick(cb1, 0);
} else
bench.end(n);
}
function cb1(arg1) {
if (--n) {
if (n % 4 === 0)
if (--counter) {
if (counter % 4 === 0)
process.nextTick(cb4, 3.14, 1024, true, false);
else if (n % 3 === 0)
else if (counter % 3 === 0)
process.nextTick(cb3, 512, true, null);
else if (n % 2 === 0)
else if (counter % 2 === 0)
process.nextTick(cb2, false, 5.1);
else
process.nextTick(cb1, 0);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/process/next-tick-depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const bench = common.createBenchmark(main, {
process.maxTickDepth = Infinity;

function main({ n }) {

let counter = n;
bench.start();
process.nextTick(onNextTick);
function onNextTick() {
if (--n)
if (--counter)
process.nextTick(onNextTick);
else
bench.end(n);
Expand Down

0 comments on commit a957f24

Please sign in to comment.