forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(web): optimize encodeInto() (denoland#15922)
- Loading branch information
1 parent
6154188
commit 5fe660e
Showing
5 changed files
with
126 additions
and
164 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,23 @@ | ||
// 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) : 1000000; | ||
|
||
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)); | ||
} | ||
|
||
const encoder = new TextEncoder(); | ||
const data = "hello world"; | ||
const out = new Uint8Array(100); | ||
|
||
bench(() => encoder.encodeInto(data, out)); |
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
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
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
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