Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timers: clean up for readability #17279

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion benchmark/timers/immediate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const common = require('../common.js');

const bench = common.createBenchmark(main, {
thousands: [2000],
thousands: [5000],
type: ['depth', 'depth1', 'breadth', 'breadth1', 'breadth4', 'clear']
});

Expand Down Expand Up @@ -88,6 +88,7 @@ function breadth1(N) {

// concurrent setImmediate, 4 arguments
function breadth4(N) {
N /= 2;
var n = 0;
bench.start();
function cb(a1, a2, a3, a4) {
Expand All @@ -101,6 +102,7 @@ function breadth4(N) {
}

function clear(N) {
N *= 4;
bench.start();
function cb(a1) {
if (a1 === 2)
Expand Down
4 changes: 2 additions & 2 deletions benchmark/timers/set-immediate-breadth-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function main(conf) {
bench.start();
for (let i = 0; i < N; i++) {
if (i % 3 === 0)
setImmediate(cb3, 512, true, null);
setImmediate(cb3, 512, true, null, 512, true, null);
else if (i % 2 === 0)
setImmediate(cb2, false, 5.1);
setImmediate(cb2, false, 5.1, 512);
else
setImmediate(cb1, 0);
}
Expand Down
14 changes: 7 additions & 7 deletions benchmark/timers/set-immediate-depth-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const common = require('../common.js');
const bench = common.createBenchmark(main, {
millions: [10]
millions: [5]
});

function main(conf) {
Expand All @@ -15,29 +15,29 @@ function main(conf) {
function cb3(n, arg2, arg3) {
if (--n) {
if (n % 3 === 0)
setImmediate(cb3, n, true, null);
setImmediate(cb3, n, true, null, 5.1, null, true);
else if (n % 2 === 0)
setImmediate(cb2, n, 5.1);
setImmediate(cb2, n, 5.1, true);
else
setImmediate(cb1, n);
}
}
function cb2(n, arg2) {
if (--n) {
if (n % 3 === 0)
setImmediate(cb3, n, true, null);
setImmediate(cb3, n, true, null, 5.1, null, true);
else if (n % 2 === 0)
setImmediate(cb2, n, 5.1);
setImmediate(cb2, n, 5.1, true);
else
setImmediate(cb1, n);
}
}
function cb1(n) {
if (--n) {
if (n % 3 === 0)
setImmediate(cb3, n, true, null);
setImmediate(cb3, n, true, null, 5.1, null, true);
else if (n % 2 === 0)
setImmediate(cb2, n, 5.1);
setImmediate(cb2, n, 5.1, true);
else
setImmediate(cb1, n);
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/timers/timers-breadth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const common = require('../common.js');

const bench = common.createBenchmark(main, {
thousands: [500],
thousands: [5000],
});

function main(conf) {
Expand Down
6 changes: 3 additions & 3 deletions benchmark/timers/timers-cancel-pooled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const common = require('../common.js');
const assert = require('assert');

const bench = common.createBenchmark(main, {
thousands: [500],
millions: [5],
});

function main(conf) {
const iterations = +conf.thousands * 1e3;
const iterations = +conf.millions * 1e6;

var timer = setTimeout(() => {}, 1);
for (var i = 0; i < iterations; i++) {
Expand All @@ -24,7 +24,7 @@ function main(conf) {
clearTimeout(timer);
}

bench.end(iterations / 1e3);
bench.end(iterations / 1e6);
}

function cb() {
Expand Down
6 changes: 3 additions & 3 deletions benchmark/timers/timers-cancel-unpooled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const common = require('../common.js');
const assert = require('assert');

const bench = common.createBenchmark(main, {
thousands: [100],
millions: [1],
});

function main(conf) {
const iterations = +conf.thousands * 1e3;
const iterations = +conf.millions * 1e6;

const timersList = [];
for (var i = 0; i < iterations; i++) {
Expand All @@ -18,7 +18,7 @@ function main(conf) {
for (var j = 0; j < iterations + 1; j++) {
clearTimeout(timersList[j]);
}
bench.end(iterations / 1e3);
bench.end(iterations / 1e6);
}

function cb() {
Expand Down
6 changes: 3 additions & 3 deletions benchmark/timers/timers-insert-pooled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
const common = require('../common.js');

const bench = common.createBenchmark(main, {
thousands: [500],
millions: [5],
});

function main(conf) {
const iterations = +conf.thousands * 1e3;
const iterations = +conf.millions * 1e6;

bench.start();

for (var i = 0; i < iterations; i++) {
setTimeout(() => {}, 1);
}

bench.end(iterations / 1e3);
bench.end(iterations / 1e6);
}
6 changes: 3 additions & 3 deletions benchmark/timers/timers-insert-unpooled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ const common = require('../common.js');
const assert = require('assert');

const bench = common.createBenchmark(main, {
thousands: [100],
millions: [1],
});

function main(conf) {
const iterations = +conf.thousands * 1e3;
const iterations = +conf.millions * 1e6;

const timersList = [];

bench.start();
for (var i = 0; i < iterations; i++) {
timersList.push(setTimeout(cb, i + 1));
}
bench.end(iterations / 1e3);
bench.end(iterations / 1e6);

for (var j = 0; j < iterations + 1; j++) {
clearTimeout(timersList[j]);
Expand Down
30 changes: 21 additions & 9 deletions benchmark/timers/timers-timeout-pooled.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
'use strict';
const common = require('../common.js');

// The following benchmark measures setting up n * 1e6 timeouts,
// which then get executed on the next uv tick

const bench = common.createBenchmark(main, {
thousands: [500],
millions: [10],
});

function main(conf) {
const iterations = +conf.thousands * 1e3;
var count = 0;
const iterations = +conf.millions * 1e6;
let count = 0;

for (var i = 0; i < iterations; i++) {
setTimeout(cb, 1);
}

bench.start();
// Function tracking on the hidden class in V8 can cause misleading
// results in this benchmark if only a single function is used —
// alternate between two functions for a fairer benchmark

function cb() {
count++;
if (count === iterations)
bench.end(iterations / 1e3);
bench.end(iterations / 1e6);
}
function cb2() {
count++;
if (count === iterations)
bench.end(iterations / 1e6);
}

for (var i = 0; i < iterations; i++) {
setTimeout(i % 2 ? cb : cb2, 1);
}

bench.start();
}
Loading