Skip to content
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