summaryrefslogtreecommitdiff
path: root/benchmark/timers
diff options
context:
space:
mode:
authorJeremiah Senkpiel <fishrock123@rocketmail.com>2017-01-20 16:16:26 -0500
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2017-01-27 14:26:24 -0500
commitc74e6fe651a763f9c6be00a2908af8b703bd5976 (patch)
tree49839f5d717ea9636e36f36bf71a89a4e65abf74 /benchmark/timers
parentb19334e566650c381c4a49277b214f6ebcc55001 (diff)
downloadandroid-node-v8-c74e6fe651a763f9c6be00a2908af8b703bd5976.tar.gz
android-node-v8-c74e6fe651a763f9c6be00a2908af8b703bd5976.tar.bz2
android-node-v8-c74e6fe651a763f9c6be00a2908af8b703bd5976.zip
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>
Diffstat (limited to 'benchmark/timers')
-rw-r--r--benchmark/timers/timers-cancel-pooled.js32
-rw-r--r--benchmark/timers/timers-cancel-unpooled.js26
-rw-r--r--benchmark/timers/timers-insert-pooled.js18
-rw-r--r--benchmark/timers/timers-insert-unpooled.js27
-rw-r--r--benchmark/timers/timers-timeout-pooled.js23
5 files changed, 126 insertions, 0 deletions
diff --git a/benchmark/timers/timers-cancel-pooled.js b/benchmark/timers/timers-cancel-pooled.js
new file mode 100644
index 0000000000..47c9fea2cb
--- /dev/null
+++ b/benchmark/timers/timers-cancel-pooled.js
@@ -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');
+}
diff --git a/benchmark/timers/timers-cancel-unpooled.js b/benchmark/timers/timers-cancel-unpooled.js
new file mode 100644
index 0000000000..a040fad69e
--- /dev/null
+++ b/benchmark/timers/timers-cancel-unpooled.js
@@ -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');
+}
diff --git a/benchmark/timers/timers-insert-pooled.js b/benchmark/timers/timers-insert-pooled.js
new file mode 100644
index 0000000000..11c35319b1
--- /dev/null
+++ b/benchmark/timers/timers-insert-pooled.js
@@ -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);
+}
diff --git a/benchmark/timers/timers-insert-unpooled.js b/benchmark/timers/timers-insert-unpooled.js
new file mode 100644
index 0000000000..91eabeb04e
--- /dev/null
+++ b/benchmark/timers/timers-insert-unpooled.js
@@ -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');
+}
diff --git a/benchmark/timers/timers-timeout-pooled.js b/benchmark/timers/timers-timeout-pooled.js
new file mode 100644
index 0000000000..feaec23237
--- /dev/null
+++ b/benchmark/timers/timers-timeout-pooled.js
@@ -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);
+ }
+}