forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optimize URL serialization (denoland#15663)
- Loading branch information
1 parent
59476ab
commit a54d565
Showing
4 changed files
with
394 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("https://example.com/"); | ||
url.pathname; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.