Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve perf #444

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading