Skip to content

Commit

Permalink
perf: optimize URL serialization (denoland#15663)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed Sep 10, 2022
1 parent 59476ab commit a54d565
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 136 deletions.
22 changes: 22 additions & 0 deletions cli/bench/url_parse.js
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;
});
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ serde = { version = "1.0.136", features = ["derive"] }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
serde_v8 = { version = "0.61.0", path = "../serde_v8" }
sourcemap = "=6.0.1"
url = { version = "2.3.1", features = ["serde"] }
url = { version = "2.3.1", features = ["serde", "expose_internals"] }
v8 = { version = "0.49.0", default-features = false }

[[example]]
Expand Down
Loading

0 comments on commit a54d565

Please sign in to comment.