Created
October 4, 2021 19:33
-
-
Save tamtamchik/8ad09447ae9ad8621e268fa9921d5917 to your computer and use it in GitHub Desktop.
fetch-https.js
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
import https from 'node:https' | |
import fetch from 'node-fetch' | |
const agent = new https.Agent({ keepAlive: true }) | |
const toMb = x => `${(x / 1024 / 1024).toFixed(2)} Mb` | |
async function start () { | |
const s = process.memoryUsage() | |
for (let i = 0; i < 1000; i++) { | |
const res = await fetch('https://example.com', { agent }) | |
for await (const chunk of res.body) {} // do nothing | |
} | |
const e = process.memoryUsage() | |
for (const k of Object.keys(s)) { | |
console.log(`memoryUsage.${k}: ${toMb(s[k])} => ${toMb(e[k])} (Diff: ${(e[k]/s[k] * 100 - 100).toFixed(2)}%)` ); | |
} | |
} | |
process.on('warning', e => {}) /* console.warn(e.stack)) */ | |
start().catch(e => console.error(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment