Skip to content

Commit 94a9b56

Browse files
authored
Let's add superagent to the benchmark. closes #2730 (#2731)
* feat: added superagent to benchmark.js * feat: added custom http agent to superagent
1 parent 6db4bbe commit 94a9b56

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

benchmarks/benchmark.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..')
1010

1111
let nodeFetch
1212
const axios = require('axios')
13+
let superagent
1314
let got
1415

1516
const util = require('node:util')
@@ -85,6 +86,11 @@ const requestAgent = new http.Agent({
8586
maxSockets: connections
8687
})
8788

89+
const superagentAgent = new http.Agent({
90+
keepAlive: true,
91+
maxSockets: connections
92+
})
93+
8894
const undiciOptions = {
8995
path: '/',
9096
method: 'GET',
@@ -318,6 +324,16 @@ if (process.env.PORT) {
318324
}).catch(console.log)
319325
})
320326
}
327+
328+
experiments.superagent = () => {
329+
return makeParallelRequests(resolve => {
330+
superagent.get(dest.url).pipe(new Writable({
331+
write (chunk, encoding, callback) {
332+
callback()
333+
}
334+
})).on('finish', resolve)
335+
})
336+
}
321337
}
322338

323339
async function main () {
@@ -326,6 +342,9 @@ async function main () {
326342
nodeFetch = _nodeFetch.default
327343
const _got = await import('got')
328344
got = _got.default
345+
const _superagent = await import('superagent')
346+
// https://github.com/ladjs/superagent/issues/1540#issue-561464561
347+
superagent = _superagent.agent().use((req) => req.agent(superagentAgent))
329348

330349
cronometro(
331350
experiments,

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"@matteo.collina/tspl": "^0.1.1",
104104
"@sinonjs/fake-timers": "^11.1.0",
105105
"@types/node": "^18.0.3",
106+
"@types/superagent": "^8.1.3",
106107
"abort-controller": "^3.0.0",
107108
"axios": "^1.6.5",
108109
"borp": "^0.9.1",
@@ -128,6 +129,7 @@
128129
"sinon": "^17.0.1",
129130
"snazzy": "^9.0.0",
130131
"standard": "^17.0.0",
132+
"superagent": "^8.1.2",
131133
"tap": "^16.1.0",
132134
"tsd": "^0.30.1",
133135
"typescript": "^5.0.2",

0 commit comments

Comments
 (0)