summaryrefslogtreecommitdiff
path: root/cli/bench/tty.js
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-09-23 09:35:45 +0530
committerGitHub <noreply@github.com>2022-09-23 09:35:45 +0530
commit72af1496d9bc180b49d42976a31b331d0be1b975 (patch)
treee0cc2fba674ccf3a20e662a44263eb61b21b8c17 /cli/bench/tty.js
parentb5dfcbbcbe6be8ac0a54e14eb8aeb0557b58f55d (diff)
perf: use fast ops for tty (#15976)
Diffstat (limited to 'cli/bench/tty.js')
-rw-r--r--cli/bench/tty.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/cli/bench/tty.js b/cli/bench/tty.js
new file mode 100644
index 000000000..f86bcfd82
--- /dev/null
+++ b/cli/bench/tty.js
@@ -0,0 +1,21 @@
+// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+const queueMicrotask = globalThis.queueMicrotask || process.nextTick;
+let [total, count] = typeof Deno !== "undefined"
+ ? Deno.args
+ : [process.argv[2], process.argv[3]];
+
+total = total ? parseInt(total, 0) : 50;
+count = count ? parseInt(count, 10) : 100000;
+
+function bench(fun) {
+ const start = Date.now();
+ for (let i = 0; i < count; i++) fun();
+ const elapsed = Date.now() - start;
+ const rate = Math.floor(count / (elapsed / 1000));
+ console.log(`time ${elapsed} ms rate ${rate}`);
+ if (--total) queueMicrotask(() => bench(fun));
+}
+
+bench(() => {
+ Deno.consoleSize(0);
+});