Skip to content

Commit 7ae1632

Browse files
authored
Add benchmark for undici requests (#537)
* Avoid parsing URL for every user input We already have the hostname * Undo change
1 parent 5b94fb7 commit 7ae1632

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

benchmarks/operations/benchmark.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const modules = [
3030
module: "http-request",
3131
name: "Outgoing HTTP request (`http.request`)",
3232
},
33+
{
34+
module: "undici",
35+
name: "Outgoing HTTP request (`undici.request`)",
36+
},
3337
];
3438

3539
(async () => {

benchmarks/operations/http-request.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ const http = require("http");
33
module.exports = {
44
step: async function step() {
55
return new Promise((resolve, reject) => {
6-
const options = {
7-
hostname: "localhost",
8-
port: 10411,
9-
};
10-
11-
const req = http.request(options, (res) => {
12-
res.on("data", () => {});
6+
const req = http.request("http://localhost:10411", (res) => {
7+
res.resume();
138
res.on("end", resolve);
149
});
1510

benchmarks/operations/package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/operations/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dependencies": {
88
"@aikidosec/firewall": "file:../../build",
99
"better-sqlite3": "^11.7.2",
10-
"mongodb": "^6.9.0"
10+
"mongodb": "^6.9.0",
11+
"undici": "^7.3.0"
1112
}
1213
}

benchmarks/operations/undici.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const undici = require("undici");
2+
3+
module.exports = {
4+
step: async function step() {
5+
return await undici.request("http://localhost:10411");
6+
},
7+
};

0 commit comments

Comments
 (0)