Skip to content

Commit

Permalink
fix: improve perf of request error instantiations (#444)
Browse files Browse the repository at this point in the history
* add benchmarks
* remove call of captureStackTrace
  • Loading branch information
Uzlopak authored Jul 11, 2024
1 parent 7d850d2 commit ba04ffa
Show file tree
Hide file tree
Showing 4 changed files with 1,099 additions and 1,039 deletions.
73 changes: 73 additions & 0 deletions benchmarks/instantiate.mjs
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());
Loading

0 comments on commit ba04ffa

Please # to comment.