-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve perf of request error instantiations (#444)
* add benchmarks * remove call of captureStackTrace
- Loading branch information
Showing
4 changed files
with
1,099 additions
and
1,039 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,73 @@ | ||
import { Bench } from 'tinybench'; | ||
import { RequestError } from "../pkg/dist-src/index.js"; | ||
|
||
const bench = new Bench({ time: 100 }); | ||
|
||
const optionsWithSimpleRequest = Object.assign({}, { | ||
request: { | ||
method: "POST", | ||
url: "https://api.github.com/authorizations", | ||
headers: {}, | ||
body: { | ||
note: "test", | ||
}, | ||
}, | ||
response: { | ||
headers: {}, | ||
status: 200, | ||
url: "https://api.github.com/", | ||
data: {}, | ||
} | ||
}); | ||
|
||
const optionsWithRequestHavingClientSecretInQuery = Object.assign({}, { | ||
request: { | ||
method: "POST", | ||
url: "https://api.github.com/authorizations?client_secret=secret", | ||
headers: {}, | ||
body: { | ||
note: "test", | ||
}, | ||
}, | ||
response: { | ||
headers: {}, | ||
status: 200, | ||
url: "https://api.github.com/", | ||
data: {}, | ||
} | ||
}); | ||
|
||
const optionsWithRequestHavingAuthorizationHeader = Object.assign({}, { | ||
request: { | ||
method: "POST", | ||
url: "https://api.github.com/authorizations", | ||
headers: { | ||
authorization: "token secret123", | ||
}, | ||
body: { | ||
note: "test", | ||
}, | ||
}, | ||
response: { | ||
headers: {}, | ||
status: 200, | ||
url: "https://api.github.com/", | ||
data: {}, | ||
} | ||
}); | ||
|
||
bench | ||
.add('instantiate a simple RequestError', () => { | ||
new RequestError("test", 123, optionsWithSimpleRequest) | ||
}) | ||
.add('instantiate a RequestError with authorization header in header', () => { | ||
new RequestError("test", 123, optionsWithRequestHavingAuthorizationHeader) | ||
}) | ||
.add('instantiate a RequestError with client_secret in query', () => { | ||
new RequestError("test", 123, optionsWithRequestHavingClientSecretInQuery) | ||
}) | ||
|
||
await bench.warmup(); // make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50 | ||
await bench.run(); | ||
|
||
console.table(bench.table()); |
Oops, something went wrong.