bench: Move timers to misc/timers
authorisaacs <i@izs.me>
Tue, 12 Feb 2013 07:00:18 +0000 (23:00 -0800)
committerisaacs <i@izs.me>
Tue, 19 Feb 2013 22:14:34 +0000 (14:14 -0800)
benchmark/misc/timers.js [new file with mode: 0644]
benchmark/timers.js [deleted file]

diff --git a/benchmark/misc/timers.js b/benchmark/misc/timers.js
new file mode 100644 (file)
index 0000000..23f571b
--- /dev/null
@@ -0,0 +1,40 @@
+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);
+  }
+}
diff --git a/benchmark/timers.js b/benchmark/timers.js
deleted file mode 100644 (file)
index 095cca1..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-function next (i) {
-  if (i <= 0) return;
-  setTimeout(function () { next(i-1); }, 1);
-}
-next(700);