summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorAnatoli Papirovski <anatoli.papirovski@postmates.com>2019-03-31 12:42:26 -0700
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-04-05 05:37:11 +0200
commit2c49e8b537a5fba07568c2363ba6a594caa74c17 (patch)
tree9a2bdf0b3042ed3a165cde8ff3ff2f970424327d /benchmark
parentd3d4e10107a594a758baf2cd5e2c1258671e58c5 (diff)
downloadnode-new-2c49e8b537a5fba07568c2363ba6a594caa74c17.tar.gz
lib: make queueMicrotask faster
No longer create an additional scope within queueMicrotask in order to improve performance. PR-URL: https://github.com/nodejs/node/pull/27032 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/process/queue-microtask-breadth.js21
-rw-r--r--benchmark/process/queue-microtask-depth.js17
2 files changed, 38 insertions, 0 deletions
diff --git a/benchmark/process/queue-microtask-breadth.js b/benchmark/process/queue-microtask-breadth.js
new file mode 100644
index 0000000000..8bb33f6fde
--- /dev/null
+++ b/benchmark/process/queue-microtask-breadth.js
@@ -0,0 +1,21 @@
+'use strict';
+
+const common = require('../common.js');
+const bench = common.createBenchmark(main, {
+ n: [4e5]
+});
+
+function main({ n }) {
+ var j = 0;
+
+ function cb() {
+ j++;
+ if (j === n)
+ bench.end(n);
+ }
+
+ bench.start();
+ for (var i = 0; i < n; i++) {
+ queueMicrotask(cb);
+ }
+}
diff --git a/benchmark/process/queue-microtask-depth.js b/benchmark/process/queue-microtask-depth.js
new file mode 100644
index 0000000000..407feb1b32
--- /dev/null
+++ b/benchmark/process/queue-microtask-depth.js
@@ -0,0 +1,17 @@
+'use strict';
+const common = require('../common.js');
+const bench = common.createBenchmark(main, {
+ n: [12e5]
+});
+
+function main({ n }) {
+ let counter = n;
+ bench.start();
+ queueMicrotask(onNextTick);
+ function onNextTick() {
+ if (--counter)
+ queueMicrotask(onNextTick);
+ else
+ bench.end(n);
+ }
+}