-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: avoid unnecessary clone (#3117)
* perf(fetch): improve body mixin methods * perf: avoid unnecessary clone
- Loading branch information
Showing
3 changed files
with
46 additions
and
13 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,24 @@ | ||
import { group, bench, run } from 'mitata' | ||
import { Response } from '../../lib/web/fetch/response.js' | ||
|
||
const settings = { | ||
small: 2 << 8, | ||
middle: 2 << 12, | ||
long: 2 << 16 | ||
} | ||
|
||
for (const [name, length] of Object.entries(settings)) { | ||
const buffer = Buffer.allocUnsafe(length).map(() => (Math.random() * 100) | 0) | ||
group(`${name} (length ${length})`, () => { | ||
bench('Response#arrayBuffer', async () => { | ||
return await new Response(buffer).arrayBuffer() | ||
}) | ||
|
||
// for comparison | ||
bench('Response#text', async () => { | ||
return await new Response(buffer).text() | ||
}) | ||
}) | ||
} | ||
|
||
await run() |
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