Skip to content

Commit

Permalink
Let's add superagent to the benchmark. closes #2730 (#2731)
Browse files Browse the repository at this point in the history
* feat: added superagent to benchmark.js

* feat: added custom http agent to superagent
  • Loading branch information
eddienubes committed Feb 11, 2024
1 parent 6db4bbe commit 94a9b56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions benchmarks/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..')

let nodeFetch
const axios = require('axios')
let superagent
let got

const util = require('node:util')
Expand Down Expand Up @@ -85,6 +86,11 @@ const requestAgent = new http.Agent({
maxSockets: connections
})

const superagentAgent = new http.Agent({
keepAlive: true,
maxSockets: connections
})

const undiciOptions = {
path: '/',
method: 'GET',
Expand Down Expand Up @@ -318,6 +324,16 @@ if (process.env.PORT) {
}).catch(console.log)
})
}

experiments.superagent = () => {
return makeParallelRequests(resolve => {
superagent.get(dest.url).pipe(new Writable({
write (chunk, encoding, callback) {
callback()
}
})).on('finish', resolve)
})
}
}

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

cronometro(
experiments,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"@matteo.collina/tspl": "^0.1.1",
"@sinonjs/fake-timers": "^11.1.0",
"@types/node": "^18.0.3",
"@types/superagent": "^8.1.3",
"abort-controller": "^3.0.0",
"axios": "^1.6.5",
"borp": "^0.9.1",
Expand All @@ -128,6 +129,7 @@
"sinon": "^17.0.1",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"superagent": "^8.1.2",
"tap": "^16.1.0",
"tsd": "^0.30.1",
"typescript": "^5.0.2",
Expand Down

0 comments on commit 94a9b56

Please sign in to comment.