Skip to content

Commit

Permalink
benchmark: split timers benchmark and refactor
Browse files Browse the repository at this point in the history
The depth benchmark for timers sets a timer that sets a timer that sets
a timer that... 500K of them.

Since each timer has to wait for the next tick of the event loop this
benchmark takes a very long time to run compared to the breadth
test that is already in the file. This may be more of an event loop
benchmark than a timer benchmark.

Reduce the number of iterations for the depth test as it's really just
running the iterations in sequence, not in parallel. And even on an
infinitely fast machine, it would take over 8 minutes to run because
each tick of the event loop would have to wait 1ms before firing the
timer.

Split the depth and breadth benchmarks so that their `N` values can be
set independently.

Do some minor refactoring to the benchmarks (but no ES6 additions so
that the benchmarks can still be run with old versions of Node.js).

Refs: #9493
PR-URL: #9497
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Dec 21, 2016
1 parent e42ee4e commit 9c08a03
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
20 changes: 20 additions & 0 deletions benchmark/timers/timers-breadth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
var common = require('../common.js');

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

function main(conf) {
var N = +conf.thousands * 1e3;
var n = 0;
bench.start();
function cb() {
n++;
if (n === N)
bench.end(N / 1e3);
}
for (var i = 0; i < N; i++) {
setTimeout(cb, 1);
}
}
20 changes: 20 additions & 0 deletions benchmark/timers/timers-depth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
var common = require('../common.js');

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

function main(conf) {
var N = +conf.thousands * 1e3;
var n = 0;
bench.start();
setTimeout(cb, 1);
function cb() {
n++;
if (n === N)
bench.end(N / 1e3);
else
setTimeout(cb, 1);
}
}
41 changes: 0 additions & 41 deletions benchmark/timers/timers.js

This file was deleted.

0 comments on commit 9c08a03

Please sign in to comment.