From a54d5654a26d29dfca1162ccc5476e9224a657e9 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sat, 10 Sep 2022 09:15:16 +0530 Subject: perf: optimize URL serialization (#15663) --- cli/bench/url_parse.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 cli/bench/url_parse.js (limited to 'cli/bench/url_parse.js') 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; +}); -- cgit v1.2.3