aboutsummaryrefslogtreecommitdiff
path: root/benchmark/timers/timers-depth.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2016-11-06 16:47:41 -0800
committerRich Trott <rtrott@gmail.com>2016-11-09 19:19:04 -0800
commitef6a5cf40a7fe7f68fe85e1528970f351e31ed13 (patch)
treebc2485542f977c305b5b681a7ffd1e9ef2ac39f0 /benchmark/timers/timers-depth.js
parent1ce05ad5401447cff6df6e62e22ff5cf052e5c92 (diff)
downloadandroid-node-v8-ef6a5cf40a7fe7f68fe85e1528970f351e31ed13.tar.gz
android-node-v8-ef6a5cf40a7fe7f68fe85e1528970f351e31ed13.tar.bz2
android-node-v8-ef6a5cf40a7fe7f68fe85e1528970f351e31ed13.zip
benchmark: split timers benchmark and refactor
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: https://github.com/nodejs/node/issues/9493 PR-URL: https://github.com/nodejs/node/pull/9497 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'benchmark/timers/timers-depth.js')
-rw-r--r--benchmark/timers/timers-depth.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/benchmark/timers/timers-depth.js b/benchmark/timers/timers-depth.js
new file mode 100644
index 0000000000..d5efc5c672
--- /dev/null
+++ b/benchmark/timers/timers-depth.js
@@ -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);
+ }
+}