benchmark: add more thorough timers benchmarks
Refs: https://github.com/nodejs/node/issues/9493 PR-URL: https://github.com/nodejs/node/pull/10925 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
parent
b19334e566
commit
c74e6fe651
32
benchmark/timers/timers-cancel-pooled.js
Normal file
32
benchmark/timers/timers-cancel-pooled.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
'use strict';
|
||||||
|
var common = require('../common.js');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var bench = common.createBenchmark(main, {
|
||||||
|
thousands: [500],
|
||||||
|
});
|
||||||
|
|
||||||
|
function main(conf) {
|
||||||
|
var iterations = +conf.thousands * 1e3;
|
||||||
|
|
||||||
|
var timer = setTimeout(() => {}, 1);
|
||||||
|
for (var i = 0; i < iterations; i++) {
|
||||||
|
setTimeout(cb, 1);
|
||||||
|
}
|
||||||
|
var next = timer._idlePrev;
|
||||||
|
clearTimeout(timer);
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
|
||||||
|
for (var j = 0; j < iterations; j++) {
|
||||||
|
timer = next;
|
||||||
|
next = timer._idlePrev;
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bench.end(iterations / 1e3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cb() {
|
||||||
|
assert(false, 'Timer should not call callback');
|
||||||
|
}
|
26
benchmark/timers/timers-cancel-unpooled.js
Normal file
26
benchmark/timers/timers-cancel-unpooled.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
'use strict';
|
||||||
|
var common = require('../common.js');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var bench = common.createBenchmark(main, {
|
||||||
|
thousands: [100],
|
||||||
|
});
|
||||||
|
|
||||||
|
function main(conf) {
|
||||||
|
var iterations = +conf.thousands * 1e3;
|
||||||
|
|
||||||
|
var timersList = [];
|
||||||
|
for (var i = 0; i < iterations; i++) {
|
||||||
|
timersList.push(setTimeout(cb, i + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
for (var j = 0; j < iterations + 1; j++) {
|
||||||
|
clearTimeout(timersList[j]);
|
||||||
|
}
|
||||||
|
bench.end(iterations / 1e3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cb() {
|
||||||
|
assert(false, 'Timer ' + this._idleTimeout + ' should not call callback');
|
||||||
|
}
|
18
benchmark/timers/timers-insert-pooled.js
Normal file
18
benchmark/timers/timers-insert-pooled.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
var common = require('../common.js');
|
||||||
|
|
||||||
|
var bench = common.createBenchmark(main, {
|
||||||
|
thousands: [500],
|
||||||
|
});
|
||||||
|
|
||||||
|
function main(conf) {
|
||||||
|
var iterations = +conf.thousands * 1e3;
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
|
||||||
|
for (var i = 0; i < iterations; i++) {
|
||||||
|
setTimeout(() => {}, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bench.end(iterations / 1e3);
|
||||||
|
}
|
27
benchmark/timers/timers-insert-unpooled.js
Normal file
27
benchmark/timers/timers-insert-unpooled.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
var common = require('../common.js');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var bench = common.createBenchmark(main, {
|
||||||
|
thousands: [100],
|
||||||
|
});
|
||||||
|
|
||||||
|
function main(conf) {
|
||||||
|
var iterations = +conf.thousands * 1e3;
|
||||||
|
|
||||||
|
var timersList = [];
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
for (var i = 0; i < iterations; i++) {
|
||||||
|
timersList.push(setTimeout(cb, i + 1));
|
||||||
|
}
|
||||||
|
bench.end(iterations / 1e3);
|
||||||
|
|
||||||
|
for (var j = 0; j < iterations + 1; j++) {
|
||||||
|
clearTimeout(timersList[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cb() {
|
||||||
|
assert(false, 'Timer ' + this._idleTimeout + ' should not call callback');
|
||||||
|
}
|
23
benchmark/timers/timers-timeout-pooled.js
Normal file
23
benchmark/timers/timers-timeout-pooled.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
'use strict';
|
||||||
|
var common = require('../common.js');
|
||||||
|
|
||||||
|
var bench = common.createBenchmark(main, {
|
||||||
|
thousands: [500],
|
||||||
|
});
|
||||||
|
|
||||||
|
function main(conf) {
|
||||||
|
var iterations = +conf.thousands * 1e3;
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < iterations; i++) {
|
||||||
|
setTimeout(cb, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
|
||||||
|
function cb() {
|
||||||
|
count++;
|
||||||
|
if (count === iterations)
|
||||||
|
bench.end(iterations / 1e3);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user