summaryrefslogtreecommitdiff
path: root/cli/bench
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-09-10 09:15:16 +0530
committerGitHub <noreply@github.com>2022-09-10 09:15:16 +0530
commita54d5654a26d29dfca1162ccc5476e9224a657e9 (patch)
tree18ef0365e9f3d4e25fffc5f6d2f9be044b7143f1 /cli/bench
parent59476ab96d04e92c2f00704672e692fc9d2b12a2 (diff)
perf: optimize URL serialization (#15663)
Diffstat (limited to 'cli/bench')
-rw-r--r--cli/bench/url_parse.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/cli/bench/url_parse.js b/cli/bench/url_parse.js
new file mode 100644
index 000000000..d19793f63
--- /dev/null
+++ b/cli/bench/url_parse.js
@@ -0,0 +1,22 @@
+// 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) : 10000000;
+
+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(() => {
+ const url = new URL("http://example.com/");
+ url.pathname;
+});