summaryrefslogtreecommitdiff
path: root/benchmark/timers
diff options
context:
space:
mode:
authorAndreas Madsen <amwebdk@gmail.com>2016-01-29 21:40:04 +0100
committerRod Vagg <rod@vagg.org>2016-02-26 20:28:45 +1100
commitd9079ab8013ba2c2a4704a2cca6fe3fcc0a1ecdd (patch)
treeca1875d33a81d5679e96e9be4afce1d2083bc6ac /benchmark/timers
parent1d7c37018f619ebd4c7d538a4b65461cc447728d (diff)
downloadandroid-node-v8-d9079ab8013ba2c2a4704a2cca6fe3fcc0a1ecdd.tar.gz
android-node-v8-d9079ab8013ba2c2a4704a2cca6fe3fcc0a1ecdd.tar.bz2
android-node-v8-d9079ab8013ba2c2a4704a2cca6fe3fcc0a1ecdd.zip
benchmark: move misc to categorized directories
PR-URL: https://github.com/nodejs/node/pull/5177 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Diffstat (limited to 'benchmark/timers')
-rw-r--r--benchmark/timers/timers.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/benchmark/timers/timers.js b/benchmark/timers/timers.js
new file mode 100644
index 0000000000..13b18fffc5
--- /dev/null
+++ b/benchmark/timers/timers.js
@@ -0,0 +1,41 @@
+'use strict';
+var common = require('../common.js');
+
+var bench = common.createBenchmark(main, {
+ thousands: [500],
+ type: ['depth', 'breadth']
+});
+
+function main(conf) {
+ var n = +conf.thousands * 1e3;
+ if (conf.type === 'breadth')
+ breadth(n);
+ else
+ depth(n);
+}
+
+function depth(N) {
+ var n = 0;
+ bench.start();
+ setTimeout(cb);
+ function cb() {
+ n++;
+ if (n === N)
+ bench.end(N / 1e3);
+ else
+ setTimeout(cb);
+ }
+}
+
+function breadth(N) {
+ var n = 0;
+ bench.start();
+ function cb() {
+ n++;
+ if (n === N)
+ bench.end(N / 1e3);
+ }
+ for (var i = 0; i < N; i++) {
+ setTimeout(cb);
+ }
+}