diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2018-05-05 19:50:21 +0200 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2018-05-22 23:26:12 +0400 |
commit | 23a56e0c28cd828ef0cabb05b30e03cc8cb57dd5 (patch) | |
tree | c389f61071481a949bcea2d78bffb687ec138221 /benchmark/timers/timers-insert-unpooled.js | |
parent | 6f6f7f749bd6847278836832542116f371ab3aa6 (diff) | |
download | android-node-v8-23a56e0c28cd828ef0cabb05b30e03cc8cb57dd5.tar.gz android-node-v8-23a56e0c28cd828ef0cabb05b30e03cc8cb57dd5.tar.bz2 android-node-v8-23a56e0c28cd828ef0cabb05b30e03cc8cb57dd5.zip |
timers: use only a single TimerWrap instance
Hang all timer lists off a single TimerWrap and use the PriorityQueue
to manage expiration priorities. This makes the Timers code clearer,
consumes significantly less resources and improves performance.
PR-URL: https://github.com/nodejs/node/pull/20555
Fixes: https://github.com/nodejs/node/issues/16105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'benchmark/timers/timers-insert-unpooled.js')
-rw-r--r-- | benchmark/timers/timers-insert-unpooled.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/benchmark/timers/timers-insert-unpooled.js b/benchmark/timers/timers-insert-unpooled.js index 1f1c5155a7..232cc7c31a 100644 --- a/benchmark/timers/timers-insert-unpooled.js +++ b/benchmark/timers/timers-insert-unpooled.js @@ -4,18 +4,26 @@ const assert = require('assert'); const bench = common.createBenchmark(main, { n: [1e6], + direction: ['start', 'end'] }); -function main({ n }) { +function main({ direction, n }) { const timersList = []; + var i; bench.start(); - for (var i = 0; i < n; i++) { - timersList.push(setTimeout(cb, i + 1)); + if (direction === 'start') { + for (i = 1; i <= n; i++) { + timersList.push(setTimeout(cb, i)); + } + } else { + for (i = n; i > 0; i--) { + timersList.push(setTimeout(cb, i)); + } } bench.end(n); - for (var j = 0; j < n + 1; j++) { + for (var j = 0; j < n; j++) { clearTimeout(timersList[j]); } } |